I\'m looking for a server example that would combine a http handler on port 80 and a protobuf handler on another port in the same jar. Thanks!
For my perspective, create different ServerBootstraps are not fully right way, because it will lead to create unused entities, handlers, double initialization, possible inconsistence between them, EventLoopGroups sharing or cloning, etc.
Good alternative is just to create multiple channels for all required ports in one Bootstrap server. If take "Writing a Discard Server" example from Netty 4.x "Getting Started", we should replace
// Bind and start to accept incoming connections.
ChannelFuture f = b.bind(port).sync(); // (7)
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
// shut down your server.
f.channel().closeFuture().sync()
With
List<Integer> ports = Arrays.asList(8080, 8081);
Collection<Channel> channels = new ArrayList<>(ports.size());
for (int port : ports) {
Channel serverChannel = bootstrap.bind(port).sync().channel();
channels.add(serverChannel);
}
for (Channel ch : channels) {
ch.closeFuture().sync();
}
I don't know what exactly you are looking for. Its just about creating two different ServerBootstrap instances, configure them and call bind(..) thats it.