ChannelHandler不是可共享的Handler(ChannelHandler is not a sharable Handler)

编程入门 行业动态 更新时间:2024-10-24 14:19:14
ChannelHandler不是可共享的Handler(ChannelHandler is not a sharable Handler)

好吧所以我正在尝试使用Netty 4.0.19(顺便说一下这很棒)并且有一个连接工作正常,但是一旦有多个连接,就会出现一个错误,即处理程序不是共享处理程序而且不能有多个项目。

这是我的Handler类: ChannelManager.java

我在想,也许每个连接都需要自己的处理程序,但后来我不确定如何在当前环境中实现它。 有什么建议或想法吗?

编辑:我不知道如何在谷歌上问这个问题...所以,如果这个问题已经存在,请原谅。

我认为它与代码中的第59行有关。 我看到一些ChannelInitializer的使用,但我不知道如何使用它。

Alright so I am experimenting with Netty 4.0.19 (which is great by the way) and having one connection works fine, but once there are multiple connections there is an error that the handler is not a shared handler and cannot have multiple items.

This is my Handler class: ChannelManager.java

I was thinking, maybe every connection needs its own handler, but then I'm not sure how I will implement that in my current environment. Any suggestions or ideas?

EDIT : I wasn't sure how to ask this question on google... so excuse me if this question already exists.

I think it has something to do with line 59 in the code. I saw some use of a ChannelInitializer but I don't know how to use that.

最满意答案

如果您的处理程序可以在多个客户端之间共享,则需要使用以下方法对该类进行注释:

@ChannelHandler.Sharable

if your handler can be shared between multiple clients you need to annotate the class with:

@ChannelHandler.Sharable

更多推荐

本文发布于:2023-07-27 17:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293597.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ChannelHandler   Handler   sharable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!