2013-03-27 2 views
0

새로운 기능과 애플리케이션에서 사용하는 방법을 확인하기 위해 Netty 4 예제를 시작했습니다. Discard Server 튜토리얼부터 시작했습니다. 나는 그것을 썼고 달리고 그것이 효과가 있었다. 텔넷 명령을 통해 확인할 수 있습니다. 그러나 netty 사이트에있는 것을 기반으로 콘솔에 기록 된 것을 볼 수 있어야합니다. 하지만 앱이 실행 중이지만 나는 그것을 볼 수 없습니다.Netty 4 Beta 3 문제

또한 경고 메시지가 표시됩니다. 경고 : 사용중인 플랫폼이 직접 버퍼에 안정적으로 액세스하기위한 완전한 하위 수준 API를 제공하지 않습니다. 명시 적으로 요청하지 않는 한, OutOfMemoryError를 가져올 잠재적 위험을 피하기 위해 힙 버퍼가 항상 선호됩니다.

은 코드 내가 작성한된다

/** 
* 
*/ 
package com.smsgh.Discard; 

import java.net.InetSocketAddress; 

import io.netty.bootstrap.ServerBootstrap; 
import io.netty.channel.Channel; 
import io.netty.channel.ChannelFuture; 
import io.netty.channel.ChannelInitializer; 
import io.netty.channel.ChannelOption; 
import io.netty.channel.nio.NioEventLoopGroup; 
import io.netty.channel.socket.SocketChannel; 
import io.netty.channel.socket.nio.NioServerSocketChannel; 

/** 
* @author Arsene 
* 
*/ 
public class DiscardServer { 

    /** 
    * 
    */ 
    public DiscardServer() { 
    } 

    public static void main(String[] args){ 

     // Instance of the Server bootstrap 
     ServerBootstrap bootstrap = new ServerBootstrap(); 

     try{ 
      // Bootstrap group is used to handle incoming connections and handle the I/O of 
      // those connections 
      bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()); 

      // Set the factory 
      bootstrap.channel(NioServerSocketChannel.class); 

      // Add a child channel handler 
      bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { 

       @Override 
       protected void initChannel(SocketChannel ch) throws Exception { 
        ch.pipeline().addLast(new DiscardServerHandler()); 
       } 
      }); 

      // add the options 
      bootstrap.childOption(ChannelOption.TCP_NODELAY, true); 
      bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); 

      ChannelFuture future = bootstrap.bind(new InetSocketAddress(8889)).sync(); 
      future.channel().closeFuture().sync(); 
     } 
     catch(Exception ex){ 
      ex.printStackTrace(); 
     } 
     finally{ 
      bootstrap.shutdown(); 
     } 
    } 
} 

이 서버 핸들러 코드 :

/** 
* 
*/ 
package com.smsgh.Discard; 

import io.netty.buffer.ByteBuf; 
import io.netty.channel.ChannelHandlerContext; 
import io.netty.channel.ChannelInboundByteHandlerAdapter; 

/** 
* @author Arsene 
* 
*/ 
public class DiscardServerHandler extends ChannelInboundByteHandlerAdapter { 

    /** 
    * 
    */ 
    public DiscardServerHandler() { 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see 
    * io.netty.channel.ChannelInboundByteHandlerAdapter#inboundBufferUpdated 
    * (io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf) 
    */ 
    @Override 
    protected void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) 
      throws Exception { 

     // Here we manipulate the data received 
     while(in.isReadable()){ 
      System.out.println((char)in.readByte()); 
      System.out.flush(); 
     } 
     in.clear(); 
    } 

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

사람이 무엇이 잘못되었는지 말해 줄래? 고맙습니다

답변

0

나는이 문제점을 보았다. 파이프 라인에 들어오는 인코더 나 디코더를 추가하지 않았습니다.