Detecting clsoed socket on OutputStream.Write



Hi

I'm working on the client portion of a client-server app. The client
application is fairly straightforward - it sends messages to the server
app and blocks whilst waiting for a response. Communication in the
client is implemented using the Java Socket class.

In certain circumstances (that is, in response to certain messages),
the server may terminate the socket (the server is a C app and uses
closesocket to do this). What I'm trying to do is detect that this has
happened when I come to send the next message. I would expect an
IOException to be thrown from OutputStream.Write or .Flush. I can
detect this, and then create a new socket on the client and reconnect.

However, the exception is rarely fired, despite multiple calls to
OutputStream.write. Instead, I get an exception on InputStream.read.

Having looked through the archive for this group, I can see that
similar issues to this have been raised before, although they usually
revolve around "how do I detect when the network cable has been
unplugged?", which seems like a different issue to me. In my case, the
socket should have been closed on the server side, so it seems that the
write should fail.

In there a definitive answer to this, or is it just one of those
vagaries of TCP/IP that we have to accept?

Thanks

David

.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • RE: Using kerberosSecurity Throws Security Exception
    ... I am experiencing this error while trying to use a Windows XP client ... application to access a web service located on a W2k3 server. ... client app on the server, ... > Account with a Custom Principal Name using SetSPN.exe utility. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Questions about Remoting, objects, threading. lease lifetime and object cleanup, and a couple of
    ... so long as the Client app is ... always refering to the same server object. ... it sets its ClassOne object to nothing and goes away. ... >>The client app at some point is going to become an ASP.Net app also. ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)