文書番号http://netty.io/docs/stable/guide/html/をご覧ください。セクション9までスクロールして、アプリケーションをシャットダウンします。
package org.jboss.netty.example.time;
public class TimeServer {
static final ChannelGroup allChannels = new DefaultChannelGroup("time-server"(35));
public static void main(String[] args) throws Exception {
...
ChannelFactory factory = ...;
ServerBootstrap bootstrap = ...;
...
Channel channel = bootstrap.bind(...);
allChannels.add(channel);
...
// Shutdown code
ChannelGroupFuture future = allChannels.close();
future.awaitUninterruptibly();
factory.releaseExternalResources();
}
}
あなたハンドラが必要:
あなたのメインのアプリAHSは、のようなものを見て
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
TimeServer.allChannels.add(e.getChannel());
}
あなたが持っている:ChannelGroup
2の 1.ストアすべてのチャンネルをシャットすべてのチャネルを閉じ、リソースを解放します。
これが役に立ちます。
私は単純にnettyの例(org.jboss.netty.example.http.snoop)で与えられたHttpSnoopServerを使用しています。そして、私はサーバーハンドラで次のコードを参照してください。 ChannelFuture future = e.getChannel()。write(レスポンス); //書き込み操作が完了した後に非キープアライブ接続を閉じます。 if(!keepAlive) { future.addListener(ChannelFutureListener.CLOSE); } ' あなたが指定したものと似ていませんか? –