From 70544aee1ebd782ca32a0009167605f14af3cc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E4=BF=8A=E9=94=8B?= Date: Tue, 9 Nov 2021 09:10:54 +0800 Subject: [PATCH] init project --- .../corundumstudio/socketio/SimpleServer.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/corundumstudio/socketio/SimpleServer.java diff --git a/src/main/java/com/corundumstudio/socketio/SimpleServer.java b/src/main/java/com/corundumstudio/socketio/SimpleServer.java new file mode 100644 index 0000000..76db929 --- /dev/null +++ b/src/main/java/com/corundumstudio/socketio/SimpleServer.java @@ -0,0 +1,59 @@ +package com.corundumstudio.socketio; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +/** + * Netty Demo + * @author ye.jf + * @version 0.1.0 + * @date 2021/11/9 9:05 + * @copyright Wonhigh Information Technology (Shenzhen) Co.,Ltd. + */ +public class SimpleServer { + + public static void main(String[] args) throws Exception { + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap b = new ServerBootstrap(); + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .handler(new SimpleServerHandler()) + .childHandler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + } + }); + + ChannelFuture f = b.bind(8888).sync(); + + f.channel().closeFuture().sync(); + } finally { + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + } + + private static class SimpleServerHandler extends ChannelInboundHandlerAdapter { + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + System.out.println("channelActive"); + } + + @Override + public void channelRegistered(ChannelHandlerContext ctx) throws Exception { + System.out.println("channelRegistered"); + } + + @Override + public void handlerAdded(ChannelHandlerContext ctx) throws Exception { + System.out.println("handlerAdded"); + } + } + +}