-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEchoServer.java
35 lines (30 loc) · 1.16 KB
/
EchoServer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cn.rookiex;
import cn.rookiex.coon.server.timer.TimerHolder;
import cn.rookiex.robot.ExampleRobotFactory;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
/**
* @author rookieX 2022/12/5
*/
public class EchoServer {
public static void main(String[] args) throws Exception {
ExampleRobotFactory exampleRobotFactory = new ExampleRobotFactory();
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup(4);
TimerHolder.init();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup,workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(exampleRobotFactory.getServerChannelInitializer());
ChannelFuture f = b.bind(8090).sync();
f.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}