Claudio Ferraro
Claudio Ferraro

Reputation: 4721

Multiple send() method calls and 1 receive method. Is this normal?

If on the client side I connect to a server and invoke the Send() method on the socket sending short data many times, is it normal that the server sometimes receives only one 'packet' which contains all the accumulated data which is the sum of many sending methods?

Upvotes: 1

Views: 355

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597530

Yes, that is completely normal, for TCP stream-based sockets anyway. By default, the Nagle algorithm for send coalescing is enabled, which reduces the number of packets that are transmitted in a small amount of time. You have to disable the algorithm if you want each send() to transmit its own packet. Sometimes that is needed in special circumstances, but usually the default behavior is adequate and desirable for most socket uses.

Upvotes: 0

James M
James M

Reputation: 16718

Yes. TCP is a stream, there's no concept of an individual "packet" - you should expect to receive everything one byte at a time, everything merged together or anything in between.

The only guarantees are that no data will be lost, and that it'll arrive in the same order you sent it.

Upvotes: 5

Related Questions