简体   繁体   中英

Netty channelActive not working when adding handler from other

I have a AuthenticationHandler extends ChannelHandlerAdapter and in the channelRead a check if the user is valid. If so, i add a new handler ( ServerHandler ) to recive all other messages.

ctx.pipeline().addLast(new ServerHandler());
ctx.pipeline().remove(this);

The problem is, that the channelActive mehod is not executed. But i need this to add the client to a list with all clients. Is there an other way to do this? Maybe someone can help! Is the problem that I'm using Netty 5.0.0 Alpha 2? But this should work, does it?

channelActive is only executed when the Channel becomes active, which in terms of TCP means when the connection was established. If you add a ChannelHandler after the Channel was connected it will not see the active event anymore.

Better override handlerAdded(...) which is guaranteed to be called in all cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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