I need to create a server application using Netty which will allow multiple socket connections on the same port. That is, I need to be able to bind multiple ServerBootStrap objects to the same port. Is this possible using Netty? My code looks like this:
@Override
public void startServer() {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR,true)
.option(ChannelOption.SO_BACKLOG, 1)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.AUTO_CLOSE, false)
.option(ChannelOption.TCP_NODELAY, true)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch)
throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new TWebMessageDecoder(logger));
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(serverHandler);
}
});
ChannelFuture f = b.bind(Utils.getPort(getConntype(), config))
.sync();
f.channel().closeFuture().sync();
} catch (Exception e) {
...
} finally {
...
}
}
I am getting the exception: Address already in use