// Accept the connection and make it non-blocking
SocketChannel
socketChannel = serverSocketChannel.accept();
Socket socket =
socketChannel.socket();
//socket.setSoTimeout(1000*10);//it will be
timeout if idle more than 10s
//after testing, i found the parameter
in socketchannel didnot work
//the following is what i google:
//you don‘t need a timeout,
//because SC‘s (SC means SocketChannel) do a
non-blocking Connect, and send a message to the Selector with message type
CONNECTED when that becomes the case
//in the protosocket, read method is a blocking invocation, so it need a "timeout" parameter ,in case some evil connection
parameter "timeout" in socketchannel does not work
原文:http://www.cnblogs.com/silentjesse/p/3543946.html