Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 绑定后关闭通道_Java_Netty - Fatal编程技术网

Java 绑定后关闭通道

Java 绑定后关闭通道,java,netty,Java,Netty,我在看一个简单的echo客户端和服务器。当服务器绑定到端口时,我们通过调用sync()等待绑定完成。在此之后,通道将关闭,如下所示: ChannelFuture f = b.bind(PORT).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); 问:为什么要关闭这个频道?这不会关闭接受连接的频道吗?我想我发现了。f、 channel().closeFuture()实际上并不关

我在看一个简单的echo客户端和服务器。当服务器绑定到端口时,我们通过调用sync()等待绑定完成。在此之后,通道将关闭,如下所示:

ChannelFuture f = b.bind(PORT).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();

问:为什么要关闭这个频道?这不会关闭接受连接的频道吗?

我想我发现了。f、 channel().closeFuture()实际上并不关闭future,而是只获取对future的引用,该引用在调用close时触发。如果我错了,请纠正我。我们不会在这里等待绑定以任何方式完成。它已经完成了。它不是一种阻塞方法,也不是一种有前途的异步方法。它是否用于在服务器通道关闭之前阻塞应用程序。。?我不是sure@EJP:如果已经完成,那么从bind().sync()返回的ChannelFuture具体是什么?