クライアントチャネルハンドラーでクライアントクライアント/サーバーを動的に構築することは可能ですか? 可能であれば、どうすればそれを達成できますか? (これを試してみましたが、bootstrap.connectを使用して接続するときに子クライアントの構築に失敗しましたが、特定のポートにバインドする子サーバーの構築に成功しましたが、理由はわかりません)
クライアントが最初に接続したサーバーではなく、他のサーバー/クライアントと動的に通信する上記の機能を実現するためのより良い方法はありますか?
追加: 次 のようなコードの一部:
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.awaitUninterruptively().getChannel();で失敗しました。、削除しても接続に失敗します: !future.isSuccess()==true