Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在指定范围内连续循环_Java_Loops_While Loop_Infinite Loop_Inetaddress - Fatal编程技术网

Java 在指定范围内连续循环

Java 在指定范围内连续循环,java,loops,while-loop,infinite-loop,inetaddress,Java,Loops,While Loop,Infinite Loop,Inetaddress,我正在制作一个Java应用程序,它将循环通过我的DHCP表并尝试连接到多个设备。我正在一个IP范围内循环,但希望在应用程序关闭之前持续循环该范围。 连续循环的最佳实践是什么?将startip的值设置两次,然后在达到最大范围后将startip设置回原始值?以下是我目前拥有的: public void loopFTP(String startIP, String endIP, int timeout) throws SocketException, IOException { InetAdd

我正在制作一个Java应用程序,它将循环通过我的DHCP表并尝试连接到多个设备。我正在一个IP范围内循环,但希望在应用程序关闭之前持续循环该范围。 连续循环的最佳实践是什么?将
startip
的值设置两次,然后在达到最大范围后将
startip
设置回原始值?以下是我目前拥有的:

public void loopFTP(String startIP, String endIP, int timeout) throws SocketException, IOException {
    InetAddress startAsIP = InetAddresses.forString(startIP);
    InetAddress endAsIP = InetAddresses.forString(endIP);
    while(InetAddresses.coerceToInteger(startAsIP) <= InetAddresses.coerceToInteger(endAsIP)){
        System.out.println(startAsIP);
        attemptConnection(startAsIP, timeout);
        startAsIP = InetAddresses.increment(startAsIP);

    }
}
public void loopFTP(String startIP、String endIP、int timeout)抛出SocketException、IOException{
InetAddress startAsIP=InetAddresses.forString(startIP);
InetAddress endAsIP=InetAddresses.forString(endIP);

while(InetAddresses.impresseToInteger(startAsIP)如果循环应该是无限的,那么可以使用
for(;;)
while(true)
循环

当到达范围结束时,只需根据
startIP
值重置
startAsIP

public void loopFTP(String startIP, String endIP, int timeout) throws SocketException, IOException {
    InetAddress startAsIP = InetAddresses.forString(startIP);
    InetAddress endAsIP = InetAddresses.forString(endIP);
    while(true){

        System.out.println(startAsIP);
        attemptConnection(startAsIP, timeout);

        if(InetAddresses.coerceToInteger(startAsIP) <= InetAddresses.coerceToInteger(endAsIP))
            startAsIP = InetAddresses.increment(startAsIP);
        else
            startAsIP = InetAddresses.forString(startIP);


    }
}
public void loopFTP(String startIP、String endIP、int timeout)抛出SocketException、IOException{
InetAddress startAsIP=InetAddresses.forString(startIP);
InetAddress endAsIP=InetAddresses.forString(endIP);
while(true){
系统输出打印LN(startAsIP);
尝试连接(startAsIP,超时);

if(InetAddresses.ImpresseToInteger(startAsIP)如果循环应该是无限的,则可以使用
for(;;)
while(true)
循环

当到达范围结束时,只需根据
startIP
值重置
startAsIP

public void loopFTP(String startIP, String endIP, int timeout) throws SocketException, IOException {
    InetAddress startAsIP = InetAddresses.forString(startIP);
    InetAddress endAsIP = InetAddresses.forString(endIP);
    while(true){

        System.out.println(startAsIP);
        attemptConnection(startAsIP, timeout);

        if(InetAddresses.coerceToInteger(startAsIP) <= InetAddresses.coerceToInteger(endAsIP))
            startAsIP = InetAddresses.increment(startAsIP);
        else
            startAsIP = InetAddresses.forString(startIP);


    }
}
public void loopFTP(String startIP、String endIP、int timeout)抛出SocketException、IOException{
InetAddress startAsIP=InetAddresses.forString(startIP);
InetAddress endAsIP=InetAddresses.forString(endIP);
while(true){
系统输出打印LN(startAsIP);
尝试连接(startAsIP,超时);

if(InetAddresses.ImpresseToInteger(startAsIP)while(true)
不够吗?不确定这里是否有“最佳实践”。任何有效的都应该足够好。if(InetAddresses.ImpresseToInteger)while(true)
不够吗?不确定这里是否有“最佳实践”。任何有效的都应该足够好。这很完美。谢谢。这很完美。谢谢