2012-05-01 10 views
1

クライアントチャネルハンドラでクライアントクライアント/サーバを動的に構築することは可能でしょうか?可能であれば、どうすれば達成できますか? (私はこれを試してみましたが、bootstrap.connectを使用して接続すると子クライアントをビルドできませんでしたが、特定のポートにバインドする子サーバーを構築しました。理由はわかりません)netty - 新しいクライアントをブートストラップして、チャネルハンドラ内の他のサーバに接続できますか?

クライアントが最初に接続したサーバではなく他のサーバ/クライアントと動的に通信できるようにする上の機能を実現するためのよりよい方法です。

添加: このようなコードのいくつか:。

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(); 
} 

...... 

}これは()future.awaitUninterruptibly に失敗

さらに、getChannel()。、接続に失敗し、まだ、それを削除した場合:!future.isSuccess()==真

+0

ごめんなさい。私はあなたの質問を理解していない.. –

答えて

関連する問題