![](/img/trans.png)
[英]ServerSocketChannel in non-blocking mode is not closing properly
[英]Non Blocking ServerSocketChannel
SocketChannel socketChannel = serverSocketChannel.accept();
当Non-Blocking ServerSocketChannel返回SocketChannel时,在调用socketChannel.configureBlocking(false)
,是否需要使用socketChannel.register(selector,SelectionKey.OP_CONNECT,new ConnectionHandler)
注册SocketChannel?
我假设一旦返回了新的SocketChannel,它已经连接到远程端点,并且socketChannel.isConnectionPending()
将返回false
而socketChannel.isConnected()
将返回true
。
public class ConnectionHandler
{
public void handleConnect ( SelectionKey key )
{
SocketChannel socketChannel = SocketChannel.class.cast ( key.channel() );
socketChannel.finishConnect ();
socketChannel.register ( key.selector (), SelectionKey.OP_READ );
}
}
当Non-Blocking
ServerSocketChannel
返回SocketChannel,
调用socketChannel.configureBlocking(false),
是否需要使用socketChannel.register(selector,SelectionKey.OP_CONNECT,new ConnectionHandler)
注册SocketChannel
?
否。它已经连接。 OP_CONNECT适用于客户端。
我假设一旦返回了新的
SocketChannel
,它就已经连接到远程端点,并且socketChannel.isConnectionPending()
将返回false,而socketChannel.isConnected()
将返回true。
正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.