import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
public class MainClass {
public static void main(String[] argv) throws Exception {
String host = "localhost";
int port = 80;
InetSocketAddress addr = new InetSocketAddress(host, port);
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
System.out.println("initiating connection");
sc.connect(addr);
while (!sc.finishConnect()) {
System.out.println("doing something useless");
}
System.out.println("connection established");
sc.close();
}
}