0
我已經創建了一個名爲的MessageHandler類:的messageReceived不叫
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(
new LoggingHandler(LogLevel.INFO),
new GameServerHandler());
ch.pipeline().addLast("protobufHandler", new MessageHandler());
}
另外,我加了的messageReceiver功能,如文件說,因爲它給了我一個錯誤,我不能覆蓋它:
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
}
}
不過的messageReceived函數沒有被調用:
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.
該死的,謝謝。我現在在網站上找到了該筆記。 – Kenny 2014-10-08 10:31:21
btw不應該你的IDE抓住這種東西? – 2014-10-08 13:58:53
我使用的是netty 5.擴展'SimpleChannelInboundHandler',它要求我實現抽象的'messageReceived'。也沒有方法'channelRead0',但有一個'channelRead',我可以覆蓋。 'messageReceived'永遠不會被調用,但'channelRead'是。我的代碼正在工作,它正在做我需要的東西,但這並不適合我。任何人都可以看到實際發生的事情嗎? – 2015-11-26 09:24:10