使用netty ssl时不调用messageReceived(channelRead)函数

时间:2017-03-15 03:15:17

标签: ssl netty

我测试了我的netty secure ssl。但是,我发现无法调用自定义处理程序中的channelRead函数。我可以告诉我如何解决这个问题吗?相关代码如下:

SSLChannelInitializer

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    //SSLEngine engine = context.newEngine(ch.alloc());
    SSLEngine engine = SSLContextFactory.getServerContext().createSSLEngine();
    engine.setUseClientMode(false);
    ch.config().setAutoRead(true);
    pipeline.addLast("ssl", new SslHandler(engine));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    //InPacketHandler handler = new InPacketHandler();
    SSLInPacketHandler handler = new SSLInPacketHandler();
    ProxyFrontendHandler handler2 = new ProxyFrontendHandler();
    //handler.addListener(new PacketListener());
    pipeline.addLast("PACKET_HANDLER", handler);
    pipeline.addLast("SOCKET_CONNECTOR", handler2);
}
The customized Handler
public class SSLInPacketHandler extends SimpleChannelInboundHandler<String>{
    @Override
    public void channelRegistered(ChannelHandlerContext ctx){
        //buf = ctx.alloc().buffer(1024);
        System.out.println("connected!");
    }

    @Override
    public void channelUnregistered(ChannelHandlerContext ctx){
        //buf.release();
        System.out.println("releasing!");
        //buf = null;
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception{
        //ByteBuf result = (ByteBuf)msg;
        System.out.println("reading!");

        //byte[] result1 = new byte[result.readableBytes()];
        //result.readBytes(result1);
        //String newmsg = new String(msg);
        //result.release();

        String newmsg = msg.replace("192.168.100.224:4444","192.168.100.52:9870");
        Message message = new Message(newmsg, "192.168.100.52", 9870);
        ctx.fireChannelRead(message);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception{
        System.out.println("completion!");
    }
}

非常感谢!

此致 周

0 个答案:

没有答案