Creating a Non-Blocking Socket: requires a socket channel.
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
public class Main {
public static void main(String[] argv) throws Exception {
SocketChannel sChannel = SocketChannel.open();
sChannel.configureBlocking(false);
sChannel.connect(new InetSocketAddress("hostName", 12345));
while (!sChannel.finishConnect()) {
// Do something else
}
}
}
Related examples in the same category