Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is not a real answer to your question regarding how the Netty client thread model works. But you can use the same <code>NioClientSocketChannelFactory</code> to create single <code>ClientBootstrap</code> with multiple <code>ChannelPipelineFactory</code>s , and in turn make a large number of connections. Take a look at the example below.</p> <pre><code>public static void main(String[] args) { String host = "localhost"; int port = 8090; ChannelFactory factory = new NioClientSocketChannelFactory(Executors .newCachedThreadPool(), Executors.newCachedThreadPool()); MyHandler handler1 = new MyHandler(); PipelineFactory factory1 = new PipelineFactory(handler1); AnotherHandler handler2 = new AnotherHandler(); PipelineFactory factory2 = new PipelineFactory(handler2); ClientBootstrap bootstrap = new ClientBootstrap(factory); // At client side option is tcpNoDelay and at server child.tcpNoDelay bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); for (int i = 1; i&lt;=50;i++){ if(i%2==0){ bootstrap.setPipelineFactory(factory1); }else{ bootstrap.setPipelineFactory(factory2); } ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { future.getChannel().write("SUCCESS"); } }); } } </code></pre> <p>It also shows how different pipeline factories can be set for different connections, so based on the connection you make you can tweak your encoders/decoders in the channel pipeline.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload