在 netty 中是否可以在同一个 tcp 连接中获得多个请求?

In netty is it possible to get multiple request in same tcp connection?

在 netty 中,是否可以在第一个请求正在进行时从同一个 tcp 客户端接收第二个请求。

下面是我试过的示例代码:

public class SomethingServerHandler extends SimpleChannelInboundHandler<Object> {
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    String stringMessage = (String) msg;
    if (log.isDebugEnabled()) {
        log.debug(stringMessage);
    }
    ctx.fireChannelRead(msg);
    String[] splitMessage = stringMessage.split("::");
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if ( splitMessage.length != 2 ) {
        ctx.channel().writeAndFlush(stringMessage + "\n\r");
        return;
    }
    if ( channelRepository.get(splitMessage[0]) != null ) {
        channelRepository.get(splitMessage[0]).writeAndFlush(splitMessage[1] + "\n\r");
    }       
}

从命令行: 远程登录本地主机端口

string1

字符串2

此处,在 string1 处理完成后 10 秒后,在服务器端打印 string2。反正我可以并行处理 string2 吗?

在此先感谢您的帮助。

仅当您将工作卸载到另一个线程时。您正在阻塞 EventLoop ,这意味着它的线程上不能进行其他工作。这不仅会影响此连接,还会影响由同一 EventLoop.

处理的所有其他连接