Netty 4.0 with multiple ports with different protocol each port
I think netty is the best java networking framework I have ever known, after reading and trying sampling, I have a question:
1. What's the best way to create a network server for multiple ports with a different protocol using netty 4.0?
Each server creates:
EventLoopGroup bossGroup = new NioEventLoopGroup (); // (1)
EventLoopGroup workerGroup = new NioEventLoopGroup ();
ServerBootstrap b = new ServerBootstrap (); // (2)
Each server running inside the thread
is this the right way?
2. Website server
How to secure Websocket server for Cross origin case? I have no reference to this
Your help is greatly appreciated,
Hello
BC,
source to share
As Norman said, the important thing is that you need to separate the event loop groups so that you don't create too many threads. As long as you separate the groups of event loops, you can create as ServerBootstrap
many as you like:
EventLoopGroup bossGroup = new NioEventLoopGroup(numBossThreads);
EventLoopGroup workerGroup = new NioEventLoopGroup(numWorkerThreads);
ServerBootstrap sb1 = new ServerBootstrap();
sb1.group(bossGroup, workerGroup);
...
sb1.bind();
ServerBootstrap sb2 = new ServerBootstrap();
sb2.group(bossGroup, workerGroup);
...
sb2.bind();
ServerBootstrap sb3 = new ServerBootstrap();
sb3.group(bossGroup, workerGroup);
...
sb3.bind();
bossGroup
used to receive incoming connections and workerGroup
used to process accepted connections bossGroup
. Do some performance tests and specify the optimal numBossThreads
and numWorkerThreads
.
source to share