gpt4 book ai didi

java - Netty 5,多个客户端

转载 作者:行者123 更新时间:2023-12-01 11:36:56 26 4
gpt4 key购买 nike

我刚刚将 Netty 3 软件转换为 Netty 5,但遇到了问题。对于一个客户来说,一切都绝对没问题。我可以使用这两个解码器(它们可以正确切换)并允许我登录。

当我尝试连接另一个客户端时,无论第一个客户端是否仍然连接,都会出现问题。第一个客户端保持连接状态绝对正常,但第二个客户端根本无法连接(无法通过第一个解码器)。

Apr 26, 2015 4:51:16 AM io.netty.channel.ChannelHandlerInvokerUtil notifyOutboundHandlerException
WARNING: Failed to fail the promise because it's done already: DefaultChannelPromise@7f3386c4(failure(io.netty.util.IllegalReferenceCountException: refCnt: 0)
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:111)
at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:84)
at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:791)
at io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1278)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeWrite(DefaultChannelHandlerInvoker.java:337)
at io.netty.channel.PausableChannelEventExecutor.invokeWrite(PausableChannelEventExecutor.java:132)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:539)
at io.netty.handler.timeout.IdleStateHandler.write(IdleStateHandler.java:267)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeWrite(DefaultChannelHandlerInvoker.java:337)
at io.netty.channel.PausableChannelEventExecutor.invokeWrite(PausableChannelEventExecutor.java:132)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:539)
at io.netty.channel.ChannelHandlerAdapter.write(ChannelHandlerAdapter.java:265)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
at io.netty.channel.DefaultChannelHandlerInvoker$WriteTask.run(DefaultChannelHandlerInvoker.java:440)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:328)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412)
at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280)
at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877)
at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706)
at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661)
at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126)

这是我的 Bootstrap :

EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.TCP_NODELAY, true)
.localAddress(43594)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast("timeout", new IdleStateHandler(15, 0, 0));
p.addLast("decoder", new RS2Decoder());
p.addLast("handler", new ChannelHandler());
}
}
).bind();

第一个解码器:

http://pastebin.com/9FWzXSVE

第二个解码器:

http://pastebin.com/n2D8RDgn

还有我的 channel 处理程序:

http://pastebin.com/4mdXe5jV

最佳答案

解决方案是通过 @Sharable 注释将处理程序标记为可共享。

关于java - Netty 5,多个客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com