Socket Programming

K

Kathryn Bean

In client/server application with Datagram, a client side sends a message
to a server and puts itself to sleep. Can the client receive a replay from
the server while sleeping or will the message be lost?

How about Stream Socket?

Thank you in advance.
Kathryn
 
G

Gordon Beaton

In client/server application with Datagram, a client side sends a
message to a server and puts itself to sleep. Can the client receive
a replay from the server while sleeping or will the message be lost?

How about Stream Socket?

Replies can arrive at any time, but the application won't receive them
until it actively reads from the connection (i.e. when it isn't
sleeping). In any case, incoming data is buffered by the OS up to a
point. This is true for both datagram (UDP) and stream (TCP)
protocols.

For UDP, if the application fails to keep up with the incoming data,
the receive buffer will eventually fill and the OS will start dropping
datagrams it doesn't have room for. Obviously sleeping will increase
the risk of that happening.

TCP provides flow control. If the receiver fails to keep up and the
receive buffer fills, the sender will be prevented from sending more
data until the receiver drains some of the backlog by reading from the
stream.

Why does the client put itself to sleep after sending a request to the
server? If it has no other work to do it could just as well read from
the connection, which is essentially the same as sleeping only until a
response arrives.

Do you have a Java question?

/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

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top