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