Socket reads not blocking

M

Mark McKay

I'm working with sockets on a server/client, and am running into
problems with sending messages back and forth.

I need to send small, unusual sized packets on occassion from the
client which need to go to the server immediately, so I need to call
flush() on my output stream after every message to make sure that it's
on it's way. My server is currently designed to wait for a message,
read it's header, read the message body, send it off for processing
and then wait for the next message. Unfortunately, now having added
the call to flush(), my server now gets an EOFException when it tries
it's next read.

I was hoping this read would block waiting for the next byte of the
header rather than throwing an error. I'm having a hard time trying
to figure out a way to distinguish a socket that has been remotely
closed from a socket which has simply sent a compelete message and not
sent the next yet. Before I was flushing, my reads would block and I
could simply assume that any socket error indicated a closed
connection. Currently the two cases are indistinguishable.

Mark McKay
 
G

Gordon Beaton

Unfortunately, now having added the call to flush(), my server now
gets an EOFException when it tries it's next read.

I was hoping this read would block waiting for the next byte of the
header rather than throwing an error. I'm having a hard time trying
to figure out a way to distinguish a socket that has been remotely
closed from a socket which has simply sent a compelete message and
not sent the next yet. Before I was flushing, my reads would block
and I could simply assume that any socket error indicated a closed
connection. Currently the two cases are indistinguishable.

Are you saying that you are able to continue reading subsequent
messages, even after geting EOFException? I find that extremely hard
to believe.

The two cases *are* distinct and distinguishable. Something else is
wrong.

/gordon
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top