2015-04-27 58 views
0

的預計量。我確信這個頻道是可寫的。的Netty沒有收到消息

這是我的測試代碼:

Sending the messages

Channel channel = PluginMessageClient.getClient().getChannel(); 

for(int i = 0; i < 10; i++) 
    channel.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{1})); 

Receiving the messages

public class PluginMessageServerHandler extends SimpleChannelInboundHandler<ByteBuf> 
{ 
    @Override 
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception 
    { 
     System.out.println("test"); //Being printed 1-3 times (varies every time I run the message sending method). 
    } 
} 

任何想法,爲什麼發生這種情況?

+0

嘗試使用緩衝區並打印它,併發送不同的消息。你得到哪些消息? – igreen

回答

0

你說你的頻道是可寫的,但是連接還活着嗎? 您應該使用類:

PluginMessageClient.getClient().getChannel(); 

因爲ChannelGroup自動管理通道的生命週期:

ChannelGroup channels; 

代替。