I am doing a customized object serialization over socket, and I am
getting this "SocketException: Connection Reset" problem. Hope someone
can give me a hint.
Here is what I did:
create a socket;
get both input/output stream from the socket;
create object input/output streams from them;
the client will write a few objects and then wait to read an object;
the server read these objects and do something and write an object;
On each side, I just do this after all code:
objInStream.close();
objOutStream.close();
socket.close();
So, what else I need to get rid of this "connection reset" thing? Like
setting one of these keepALive, soLinger, or timeOut things on the
socket?
Thanks,
-b
EJP - 07 Feb 2006 05:00 GMT
> I am doing a customized object serialization over socket, and I am
> getting this "SocketException: Connection Reset" problem. Hope someone
[quoted text clipped - 13 lines]
> objOutStream.close();
> socket.close();
Two suggestions: (a) close the output stream before the input stream.
Actually you only need to close the output stream, the input close and
socket close are then redundant. (b) Don't close a socket until you have
read all the data from it, i.e. really until you have read EOF,
otherwise the writing end will get this reset condition.
Shin - 07 Feb 2006 19:52 GMT
Thanks, EJP.
I ended up letting the reader send a confirmation back to the sender
and then close everything (this, in turn, will seem to cause the
problem of reader needing to wait for a confirmation on confirmation by
sender, but so far it seems fine).
I guess a better solution would be something you suggested, by closing
the stream/socket in *some* order and, thus, ensuring no "connection
reset". I was getting the error at reader end; so the error must come
from sender closing output stream and socket. Anyway, I couldn't find
a definitive protocol in such situation to use.
Maybe I will try yours next time.
-Shin
threadsafe - 10 Feb 2006 21:56 GMT
> I am doing a customized object serialization over socket, and ...
Rather than coding your own client and server you may wish to try
components such as DualRpc (www.retrogui.com), RMI (sun.java.com) or
QuickServer (www.quickserver.org)
Regards,
Threadsafe