Kenny
Kenny

Reputation: 1142

messageReceived not called

I've created a class called MessageHandler:

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ch.pipeline().addLast(
            new LoggingHandler(LogLevel.INFO),
            new GameServerHandler());
    ch.pipeline().addLast("protobufHandler", new MessageHandler()); 
}

Also, I added the messageReceiver function, I can't override it as the documentation says because it gives me an error:

public class MessageHandler extends SimpleChannelInboundHandler<Object> {
    // @Override
    public void messageReceived(ChannelHandlerContext ctx, Object msg) {
        System.out.println(msg);
        // super.messageReceived(ctx, msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext arg0, Object arg1)
            throws Exception {
        // TODO Auto-generated method stub
    }
}

But the messageReceived function is never called:

INFO: [id: 0xbb603bfd, /127.0.0.1:54206 => /127.0.0.1:5000] ACTIVE
Oct 07, 2014 10:48:49 PM io.netty.handler.logging.LoggingHandler logMessage
INFO: [id: 0xbf711f5f, /127.0.0.1:54205 => /127.0.0.1:5000] RECEIVED(383B)
// Message printed by the Netty logger, not from my function.

Upvotes: 0

Views: 576

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23557

I netty 4.x the method you need to override and put your System.out.println(...) stuff in is channelRead0(...). Only in netty 5 its messageReceived(...).

Upvotes: 2

Related Questions