Note that there are some explanatory texts on larger screens.

plurals
  1. POnetty - Can I bootstrap a new client to connect other server in a channel handler?
    text
    copied!<p>Is it possible that I could dynamic build a client client/server in the client channel handler? If it's possible, how could you achieve it? (I have tried this but failed in the build a child client when connecting using bootstrap.connect, on the other hand, I have successfully build a child server that bind with certain port, don't know why)</p> <p>Is there a better way to achieve above functions, which make the client dynamic communicate with other servers/clients, not the server it firstly connected with but keep the connection alive?</p> <p>Addition: <em>Some of the code like this:</em></p> <pre><code>public class FileClientHandler extends SimpleChannelUpstreamHandler { ..... public void getFile(final String filename, final String md5){ // Configure the client. ClientBootstrap bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Configure the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline( new FileClientGetFileHandler(filename,md5) ); } }); // Start the connection attempt. ChannelFuture future = bootstrap.connect(new InetSocketAddress(Ip, Port)); // Wait until the connection attempt succeeds or fails. future.awaitUninterruptibly().getChannel(); if (!future.isSuccess()) { System.out.print("Connect Failure!\n"); future.getCause().printStackTrace(); bootstrap.releaseExternalResources(); return; } // 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>}</p> <p>It failed at the <em>future.awaitUninterruptibly().getChannel();</em> , if delete it, still fail at the connect : <em>!future.isSuccess()==true</em></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