It turns out everything is much easier than I thought. When creating a server, we create two EventLoopGroup(bossGroup, workerGroup) .
For example:
EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workGroup = new NioEventLoopGroup(5);
When configuring ServerBootstrap you need to add event handlers that will do all the work of communicating with the client:
bootServer.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception{ ch.pipeline().addLast(new ObjectEncoder()); ch.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(Pack.class.getClassLoader()))); ch.pipeline().addLast(new ConnectionWork()); } });
Since each new connection will call the initChannel method initChannel then everything we write in ConnectionWork will work separately for each connection, the number of connections is set in the workGroup constructor.
Connectclass, pass theChannelto it and startConnectas a separate stream that will serve one client? - Bleser