简体   繁体   English

Netty 多个客户端,断开一个影响所有

[英]Netty Multiple Clients, disconnecting one affects all

I am working on a java server-client based app and using Netty (4.0.27.Final) for TCP socket connections.我正在开发基于 Java 服务器客户端的应用程序,并使用 Netty (4.0.27.Final) 进行 TCP 套接字连接。 I have facing an issue with client side.我在客户端遇到了问题。

In client I use one BootStrap, one NioEventLoopGroup for multiple clients (100+ concurrent clients) and just call the following for each new client connection.在客户端中,我使用一个 BootStrap,一个 NioEventLoopGroup 用于多个客户端(100 多个并发客户端),并为每个新的客户端连接调用以下内容。

b.handler(new MyConnectionInitializer());
b.connect(IP, PORT).sync().channel().closeFuture().sync();

Now after doing work each client calls ctx.disconnect() .现在完成工作后,每个客户端都调用ctx.disconnect() After calling it, all the clients receive ChannelInactive and connection to server for all the clients get disconnect.调用它后,所有客户端都会收到 ChannelInactive 并且所有客户端与服务器的连接断开。 While I just want that only the client for which ctx.disconnect is called should be disconnect.虽然我只想让调用ctx.disconnect的客户端断开连接。

Should I call some other function instead of ctx.disconnect() ?我应该调用其他函数而不是ctx.disconnect()吗?

Any help appreciated.任何帮助表示赞赏。

You should use close() instead of disconnect() .您应该使用close()而不是disconnect() As far as I understand disconnect() actually closes the connection (and with it all other channels that might still be open) while close() only closes the current channel.据我了解, disconnect()实际上关闭连接(以及所有其他可能仍处于打开状态的通道),而close()仅关闭当前通道。

Please someone correct me if I wrote something wrong.如果我写错了,请有人纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM