From 897f6c094b1d3d7896d9c1f04bfd9af4d70360a8 Mon Sep 17 00:00:00 2001 From: bingor Date: Fri, 11 Nov 2022 12:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8BNetty=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.3/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes src/main/java/com/msb/model/ClientFrame.java | 52 +++++++++++ src/main/java/com/msb/socket/Server.java | 82 ++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 src/main/java/com/msb/model/ClientFrame.java create mode 100644 src/main/java/com/msb/socket/Server.java diff --git a/.gradle/6.3/executionHistory/executionHistory.lock b/.gradle/6.3/executionHistory/executionHistory.lock index 5626c2caddf39604535665a8891e6bc10099c4f7..90343c79a65ea136d127f2b2e0f03d64f8112076 100644 GIT binary patch literal 17 TcmZSXb() { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + socketChannel.pipeline().addLast(new Handler()); + } + }); + + try { + bootstrap.bind(this.port).sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + bootGroup.shutdownGracefully(); + workGroup.shutdownGracefully(); + } + } + + public static void main(String[] args) { + new Server(8888); + } + +} + +class Handler extends ChannelInboundHandlerAdapter { + + private static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { +// super.channelRead(ctx, msg); + channelGroup.forEach(channel -> { + + }); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { +// super.exceptionCaught(ctx, cause); + cause.printStackTrace(); + ctx.close(); + } +}