Mega Code Archive

 
Categories / Java Tutorial / Network
 

Creating a Non-Blocking Socket

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     }   } }