0

我有一个使用 netty 开发的服务器和客户端。在客户端使用同一通道写入几条消息后,我尝试关闭套接字(释放资源)。我已按照说明@ http://netty.io/docs/unstable/guide/html/#start.12

完成上述步骤后,客户端仍未关闭。

任何一位网络专家都可以在这里帮助我。

问候 T

4

2 回答 2

1

that code seems to be missing the call to actually close the channel. i believe you want to actually call Channel.close() before line 14.

于 2012-04-11T12:27:11.723 回答
0

我在我的代码中这样做:

public class TimeClient {
  public static void main(String[] args) throws Exception {
        ...
      ChannelFactory factory = ...;
        ClientBootstrap bootstrap = ...;
      ...
        ChannelFuture future(29) = bootstrap.connect(...);
      future.awaitUninterruptibly();(30)
        if (!future.isSuccess()) {
          future.getCause().printStackTrace();(31)
        }
      ... YOUR BUSINESS LOGIC HERE
      future.getChannel().close().awaitUninterruptibly();(32)
        factory.releaseExternalResources();(33)
  }
}
于 2012-04-13T08:55:15.187 回答