Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all, for the client, bootstrap option should not start with 'child':</p> <pre><code>bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); </code></pre> <p>Also you don't use the same port on the client and the server!!</p> <p>Second, you have no "close" strategy: when is your client suppose to know its job is done? How do you prevent the Thread from ending prematuraly? You should do this</p> <p>SERVER HANDLER</p> <pre><code>public class ServerHandler extends SimpleChannelHandler{ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e){ byte[] resp=data.getBytes();//data is a String greater than 1024bytes; ChannelBuffer buffer=ChannelBuffers.buffer(resp.length); buffer.writerBytes(resp); e.getChannel().write(buffer); buffer.clear(); e.getChannel.close(); } } </code></pre> <p>CLIENT BOOTSTRAP</p> <pre><code>public class Client{ public static void main(String[] args){ ChannelFactory channelFactory=new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap=new ClientBootstrap(channelFactory); bootstrap.getPipeline().addLast("handler", new PhoneClientHandler()); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); // Start the connection attempt. ChannelFuture future = bootstrap.connect(new InetSocketAddress("127.0.0.1",8181)); // Wait until the connection is closed or the connection attempt fails. future.getChannel().getCloseFuture().awaitUninterruptibly(); // Shut down thread pools to exit. bootstrap.releaseExternalResources(); } } </code></pre> <p>Finally, you need to understand better what you are doing by reading a lot of examples. They can be found inside <strong>org.jboss.netty.example</strong> package in the main bundled download.</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