new Thread(new Runnable() {
@Override
public void run() {
List<Socket> socketList = new ArrayList<>();
for (String ip: iplist) {
Socket socket = null;
try {
socket = new Socket(ip,23);
} catch (IOException e) {
e.printStackTrace();
}
socketList.add(socket);
}
}
}).start();
I am trying to create a new socket for each ip in iplist and add this socket to the list sockets. For this, I use a for loop. In use try ... catch, loop execution is suspended for some time when the socket connection fails. So I need a better alternative to know that the socket connection failed and force the loop to continue execution by adding a null socket to the socket list.
source
share