> Hi all,
>
[quoted text clipped - 60 lines]
>
> Matt
Matt:
I think that sooner but probably later your outbound write will fail
because there is no aknowledgement from the client socket. I had a
similar problem in a server/client program I just wrote. The only way I
could think of to get a quicker notification was to create another
thread that tries to read from the socket. When the client end is
closed the read throws an immediate IOException. No data is ever read
because the client doesn't do any writing and the read just blocks until
the socket is closed. When the IOException is thrown I close the
outbound socket and clean up.

Signature
Knute Johnson
email s/nospam/knute/
Matt - 25 Feb 2006 18:43 GMT
>> Hi all,
>>
[quoted text clipped - 73 lines]
> the socket is closed. When the IOException is thrown I close the
> outbound socket and clean up.
Thank you very much Knute,
It's surprising the fact that no support for connection monitoring is
provided by Socket... but I've tried your solution and works fine :)
I'd like to point out that, as far as i have seen, no IOException is
thrown when the client closes the connection. The readLine method call
which I use is blocking, and it just returns when the client is killed.
Anyway, it works.
Thank you very much for your help.
Matt
Steve Horsley - 27 Feb 2006 22:44 GMT
>> Hi all,
>>
[quoted text clipped - 73 lines]
> the socket is closed. When the IOException is thrown I close the
> outbound socket and clean up.
I don't think the reading is necessary. Once the TCP stack knows
that the connection is broken, the next write call will fail with
an exception anyway. The code above doesn't see it because
PrintWriter swallows exceptions, IIRC. But an OutputStreamWriter
should raise them. And you should be using an OutputStreamWriter
anyway, so you can specify the character encoding, rather than
just hoping that the platform default encoding will happen to
suit the client.
Steve