Ejemplo n.º 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));
  }
Ejemplo n.º 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)
    }
  }
Ejemplo n.º 3
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // (4)
   // Close the connection when an exception is raised.
   cause.printStackTrace();
   ctx.close();
 }
Ejemplo n.º 4
0
 @Override
 public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
   System.out.println("Registered channel");
   ctx.fireChannelRegistered();
 }
Ejemplo n.º 5
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
   cause.printStackTrace();
   ctx.close();
 }