Reputation: 1
Please review the below code. Here i am trying to listen two ports with same factory. Only one port listening right now. Please suggest how to achieve multiple port listening with same factory for same handler function for all ports.
public static void main(String[] args)
{
ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newFixedThreadPool(1));
ServerBootstrap bootstrap = new ServerBootstrap(factory);
ChannelPipelineFactory cpf = new ChannelPipelineFactory()
{
public ChannelPipeline getPipeline()
{
return Channels.pipeline(new testHandler());
}
};
bootstrap.setPipelineFactory(cpf);
bootstrap.setOption("child.tcpNoDelay", true);
ChannelGroup allChannels = new DefaultChannelGroup();
Channel serverChannel = bootstrap.bind(new InetSocketAddress(5000));
allChannels.add(serverChannel);
Channel serverChannel1 = bootstrap.bind(new InetSocketAddress(6000));
allChannels.add(serverChannel1);
bootstrap.bind(new InetSocketAddress(5000));
}
Upvotes: 0
Views: 859
Reputation: 406
You can create multiple ServerBootstrap instances. Each ServerBootstrap use a Server Channel to bind.
Upvotes: 1