2013-04-02 1 views
0

Netty 4 RC1을 사용하고 있습니다. 나는 클라이언트 측에서 내 파이프 라인을 초기화 :Netty 4 - 파이프 라인 헤드의 아웃 바운드 메시지가 무시되었습니다.

public class NodeClientInitializer extends ChannelInitializer<SocketChannel> { 

    @Override 
    protected void initChannel(SocketChannel sc) throws Exception { 
    // Frame encoding and decoding 
    sc.pipeline() 
     .addLast("logger", new LoggingHandler(LogLevel.DEBUG)) 

    // Business logic 
     .addLast("handler", new NodeClientHandler()); 
    } 
} 

NodeClientHandler는 다음과 같은 관련 코드가 있습니다

public void connect(final InetSocketAddress addr) { 
    Bootstrap bootstrap = new Bootstrap(); 
    ChannelFuture cf = null; 
    try { 
     // set up the pipeline 
     bootstrap.group(new NioEventLoopGroup()) 
     .channel(NioSocketChannel.class) 
     .handler(new NodeClientInitializer()); 

     // connect 
     bootstrap.remoteAddress(addr); 
     cf = bootstrap.connect(); 
     cf.addListener(new ChannelFutureListener() { 
     @Override 
     public void operationComplete(ChannelFuture op) throws Exception { 
      logger.info("Connect to {}", addr.toString()); 
     } 
     }); 

     cf.channel().closeFuture().syncUninterruptibly(); 
    } finally { 
     bootstrap.shutdown(); 
    } 
    } 

을 그래서, 기본적으로 내가 원하는 :

public class NodeClientHandler extends ChannelInboundByteHandlerAdapter { 
    private void sendInitialInformation(ChannelHandlerContext c) { 
    c.write(0x05); 
    } 

    @Override 
    public void channelActive(ChannelHandlerContext c) throws Exception { 
    sendInitialInformation(c); 
    } 
} 

내가 사용하여 서버에 연결을 채널이 활성화 된 후 (예 : 연결이 성공한 경우) 클라이언트의 초기 정보를 서버로 보냅니다. 할 때 그러나, c.write() 나는 다음과 같은 경고를 얻을 수없고 패키지를 보낼 수 없습니다 :

WARNING: Discarded 1 outbound message(s) that reached at the head of the pipeline. Please check your pipeline configuration. 

을 내 파이프 라인에는 아웃 바운드 핸들러가없는 알고 있지만, 내가 (이 시점에서) 하나를 필요가 있다고 생각하지 않았고 Netty가 ByteBuffer를 서버로 전송하는 데주의를 기울일 것이라고 생각했습니다. 여기 파이프 라인 구성에서 내가 뭘 잘못하고 있니?

답변

1

Netty는 채널에 쓸 경우 기본적으로 ByteBuf 유형의 메시지 만 처리합니다. ByteBuf로 포장해야합니다. ByteBuf 인스턴스를 만들려면 정적 도우미가있는 Unpooled 클래스를 참조하십시오.