import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;/**来 自 nowjava.com**/
public class Main {
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);/** from 时代Java**/
while (!sc.finishConnect()) {
doSomethingUseful();
}
System.out.println("connection established");
// Do something with the connected socket
// The SocketChannel is still nonblocking
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。