0

Java でコメットのようなサービスを作成します。サービスは最初の http ヘッダーのみを読み取り、無限ループに入り、毎秒ステータス メッセージを書き込みます。書き込みメソッドを使用してクライアントの切断を検出するにはどうすればよいですか? 私は Java 開発者ではありません。これは単なるおもちゃのプロジェクトです。答えが明らかである場合は申し訳ありません。

http にはブロックが必要なため、非ブロック読み取りを使用できません (これは正しいと思います...)

ありがとう

4

1 に答える 1

1

The write will throw an exception when the client disconnects. Check for "java.net.SocketException: Broken pipe" in your catch block to determine that a disconnect is what caused it and tidy your resources. Any other exceptions should be logged and dealt with.

于 2012-03-09T10:41:46.680 に答える