问题描述
我正在使用netty 4.0.33来构建SSL/TLS客户端/服务器.对于每个连接,我想记录一条消息,表明2个对等方之间TLS连接成功.该代码段应该放在哪里? channelActive或channelRead0?我对channelActive和channelRead0的用途有点困惑.看起来在服务器端,我们根本不需要channelActive.是真的吗?
I am using netty 4.0.33 to build a SSL/TLS client/server. For every connection, I want to log a message that TLS connection is successful between the 2 peers.Where should I put this code snippet? channelActive or channelRead0? I am a bit confused about the purpose of channelActive and channelRead0. Looks like on the server side, we don't need channelActive at all. Is that true?
推荐答案
如果您想在握手成功后做点什么,可以使用:
If you want to do something when the handshake is successful you can use:
class MyHandler extends ChannelInboundHandler { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt == SslHandshakeCompletionEvent.SUCCESS) { // Your handling logging } else { super.userEventTriggered(ctx, evt); } }}
class MyHandler extends ChannelInboundHandler { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt == SslHandshakeCompletionEvent.SUCCESS) { // Your handling logging } else { super.userEventTriggered(ctx, evt); } }}
这篇关于净值channelActive与channelRead0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!