TCP Socket Flush

N

Nuno Magalhaes

How to do a TCP socket flush in order to get the packets to their real
sizes (and not accumulate) like when we send a datagram UDP. When we
send UDP it comes with the real packet size, in other words, the packet
is sent away immediatly.

TCP accumulates. How can we send each packet individually?
 
J

Jon Skeet [C# MVP]

Nuno said:
How to do a TCP socket flush in order to get the packets to their real
sizes (and not accumulate) like when we send a datagram UDP. When we
send UDP it comes with the real packet size, in other words, the packet
is sent away immediatly.

TCP accumulates. How can we send each packet individually?

I believe you want to set the NoDelay socket option.

Jon
 
N

Nick Hounsome

Nuno Magalhaes said:
It works. Thanks.

It works for your current circumstances:

1) If your receiver gets busy it can still read more than one "packet" at
once.
2) The internet can break up your "packet" so that less than a full packet
is received in one read.

There is no way to prevent this behaviour because TCP does not support the
concept of a "packet" therefore you should always code so as to accept TCP
data in arbitrary chunks.

Contrary to popular belief even UDP packets can be broken up - just try to
send a packet that is bigger than an ethernet frame and see what happens.
 

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

Top