D
david.topham
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
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