EOFException after closing a socket

S

Stefan Weber

Hi

I do something like that on one network node (site1):

socket = new Socket(...);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(new Object());
socket.close();

On another node (lets call it site2) I frequently call

ois.readObject();

where ois is the ObjectInputStream on the same connection. I have set a
timeout for the socket at site 2. The idea is that I can do some other
work until the object actually arrived.

But unfortunately, this seems to raise problems when the socket on site
1 is closed before the object is read on site 2. In such cases, an
EOFException is thrown.
I'm not a 100% sure if this is really the reason, because it hardly
makes sense to me, because even though site1 closed the connection, the
data was sent to site2 and thus is available in the buffer...
Or does the exception arise due to another reason?

Thanks a lot! Regards,

Stefan Weber
 
S

Soren Kuula

Stefan said:
Hi

I do something like that on one network node (site1):

socket = new Socket(...);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(new Object());
socket.close();

Close oos instead ... that will flush thee stuff you are missing down
the Socket, before _that_ is closed (afterwards, automatically-cascaded,
as far as I remember).

Soren
 
V

vvk

hi,
when u close the socket, all the streams created with that socket are
closed. so when u attempt to read the streams from another node it will
araise the EOFException denotes that the socket is closed and cant
access the socket.
__Vasantha kumar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top