Пример #1
0
  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    try {
      ByteBuf recvBuf = Unpooled.copiedBuffer((ByteBuf) msg);
      byte[] buf = new byte[recvBuf.capacity()];
      recvBuf.readBytes(buf);

      String request = new String(buf, CharsetUtil.UTF_8);
      System.out.println("받는 Data : " + request);

      broadCast(ctx, request);
    } finally {
      ReferenceCountUtil.release(msg);
    }
  }
Пример #2
0
  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) { // (2)
    ByteBuf in = (ByteBuf) msg;
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      while (in.isReadable()) { // (1)
        byte readByte = in.readByte();
        baos.write(readByte);
        // System.out.flush();

        ctx.flush();
      }
      System.out.println("Msg Read: " + baos.toString());
    } finally {
      // System.out.println("finish!");
      ReferenceCountUtil.release(msg); // (2)
    }
  }