ポート80のhttpハンドラーと同じjar内の別のポートのprotobufハンドラーを組み合わせるサーバーの例を探しています。ありがとう!
7065 次
2 に答える
13
私の見解では、異なるServerBootstrapsを作成することは完全に正しい方法ではありません。これは、未使用のエンティティ、ハンドラー、二重初期化、それらの間の不整合の可能性、EventLoopGroupsの共有またはクローン作成などにつながるためです。
良い代替策は、1つのブートストラップサーバーで必要なすべてのポートに複数のチャネルを作成することです。Netty4.xの「GettingStarted」から「WritingaDiscardServer」の例をとる場合は、次のように置き換える必要があります。
// Bind and start to accept incoming connections.
ChannelFuture f = b.bind(port).sync(); // (7)
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
// shut down your server.
f.channel().closeFuture().sync()
と
List<Integer> ports = Arrays.asList(8080, 8081);
Collection<Channel> channels = new ArrayList<>(ports.size());
for (int port : ports) {
Channel serverChannel = bootstrap.bind(port).sync().channel();
channels.add(serverChannel);
}
for (Channel ch : channels) {
ch.closeFuture().sync();
}
于 2015-09-04T20:13:35.527 に答える
9
あなたが何を探しているのか正確にはわかりません。2つの異なるServerBootstrapインスタンスを作成し、それらを構成して、bind(..)を呼び出します。
于 2012-09-11T11:30:15.223 に答える