简体   繁体   English

Netty TCP Server,仅通过一个套接字连接即可处理多个请求

[英]Netty TCP Server that server multiple requests with just one socket connection

Is it possible to use Netty to implement a TCP server that performs multiple interactions (request-response) with a client using the same socket connection. 是否可以使用Netty来实现一个TCP服务器,该服务器使用相同的套接字连接与客户端执行多个交互(请求-响应)。 Any pointers/examples would be appreciated. 任何指针/示例将不胜感激。

Sure.. you can send/receive as much messages as you want. 当然,您可以发送/接收任意数量的消息。 Just don't close the channel until you are done. 只是直到完成后才关闭通道。

You can do channel.write(object) as many times as necessary before closing the channel. 在关闭通道之前,可以根据需要多次执行channel.write(object)。 Another thing is you should mention bootstrap.setOption("child.keepAlive",true) to keep the connection alive 另一件事是您应该提到bootstrap.setOption(“ child.keepAlive”,true)以保持连接有效

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

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