示例#1
0
  private void broadCast(ChannelHandlerContext ctx, String request) {
    String response = ManageSql(request.split(DELIMITER));

    response += DELIMITER;
    System.out.println("보내는 Data : " + response);
    ctx.writeAndFlush(Unpooled.copiedBuffer(response, CharsetUtil.UTF_8));
  }
示例#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)
    }
  }
示例#3
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // (4)
   // Close the connection when an exception is raised.
   cause.printStackTrace();
   ctx.close();
 }
示例#4
0
 @Override
 public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
   System.out.println("Registered channel");
   ctx.fireChannelRegistered();
 }
示例#5
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
   cause.printStackTrace();
   ctx.close();
 }