Note that there are some explanatory texts on larger screens.

plurals
  1. PONetty froze with multiple clients connection
    primarykey
    data
    text
    <p>I`m trying to test netty, but when i creating a multiple clients to connect to server, some of client just froze and never finish. Here my code( basically i used code from her <a href="https://github.com/brunodecarvalho/netty-tutorials" rel="nofollow noreferrer">https://github.com/brunodecarvalho/netty-tutorials</a> and just modify it to use a several clients):</p> <pre><code> for (int i = numthr; i > 0; i--) { Runnable runner = new Runnable() { public void run() { final Client client = new Client("localhost", 10400, nummes, 0); if (!client.start()) { System.exit(-1); return; } client.flood(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { client.stop(); } }); } }; executor.execute(runner); } </code></pre> <pre><code> public void messageReceived(Envelope message) { if (this.received.incrementAndGet() == this.messages) { System.out.println(nmb.incrementAndGet()); } } public boolean start() { // For production scenarios, use limited sized thread pools this.clientFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),1); this.channelGroup = new DefaultChannelGroup(this + "-channelGroup"); this.handler = new ClientHandler(this, this.channelGroup); ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("encoder", new Encoder()); pipeline.addLast("decoder", new Decoder()); pipeline.addLast("handler", handler); return pipeline; } }; ClientBootstrap bootstrap = new ClientBootstrap(this.clientFactory); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setPipelineFactory(pipelineFactory); boolean connected = bootstrap.connect(new InetSocketAddress(host, port)).awaitUninterruptibly().isSuccess(); if (!connected) { this.stop(); } return connected; } </code></pre> <pre><code> this.serverFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); this.channelGroup = new DefaultChannelGroup(this + "-channelGroup"); ExecutionHandler executionHandler = new ExecutionHandler( new MemoryAwareThreadPoolExecutor(270, 1048576, 1048576)); ServerBootstrap bootstrap = new ServerBootstrap(this.serverFactory); bootstrap.setPipelineFactory( new DatabaseGatewayPipelineFactory(executionHandler)); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.connectTimeoutMillis", 10000); Channel channel = bootstrap.bind(new InetSocketAddress(this.host, this.port)); if (!channel.isBound()) { this.stop(); return false; } this.channelGroup.add(channel); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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