echo 작업중

This commit is contained in:
hsoh
2022-06-29 17:27:04 +09:00
parent 9ea86143ff
commit dc68e1de84
3 changed files with 190 additions and 0 deletions
@@ -0,0 +1,72 @@
//package com.eactive.httpmockserver.socket;
//
//import java.nio.charset.StandardCharsets;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import io.netty.buffer.ByteBuf;
//import io.netty.channel.ChannelHandler.Sharable;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//
//@Component
//@Sharable
//public class EchoSocketServerHandler extends ChannelInboundHandlerAdapter {
// private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
// private int DATA_LENGTH = 2048;
// private ByteBuf buff;
//
// @Override
// public void handlerAdded(ChannelHandlerContext ctx) {
// logger.info("EchoSocketServer handlerAdded");
// buff = ctx.alloc().buffer(DATA_LENGTH);
// }
//
// @Override
// public void channelActive(ChannelHandlerContext ctx) {
// logger.info("Remote Address: " + ctx.channel().remoteAddress().toString());
// }
//
// @Override
// public void channelRead(ChannelHandlerContext ctx, Object msg) {
// logger.info("EchoSocketServer channelRead");
//// ByteBuf buf = (ByteBuf) msg;
//// byte[] bytes = new byte[buf.readableBytes()];
//// buf.readBytes(bytes);
//// String data = new String(bytes, StandardCharsets.UTF_8);
//
//// ByteBuf mBuf = (ByteBuf) msg;
//// buff.writeBytes(mBuf); // 클라이언트에서 보내는 데이터가 축적됨
//// mBuf.release();
////
//// //final ChannelFuture f = ctx.writeAndFlush(buff);
////
//// System.out.println("TcpServer: " + buff.toString());
//// ctx.writeAndFlush(buff);
//
// String message = ((ByteBuf) msg).toString();
// System.out.println("message=" + message);
// ctx.write(msg);
// }
//
// @Override
// public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
// logger.info("EchoSocketServer channelReadComplete");
// ctx.flush();
// }
//
// @Override
// public void handlerRemoved(ChannelHandlerContext ctx) {
// logger.info("EchoSocketServer handlerRemoved");
// buff = null;
// }
//
// @Override
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// ctx.close();
// cause.printStackTrace();
// }
//}