miguel_dr
miguel_dr

Reputation: 3

Nagle not being disabled by TCP_NODELAY

I want packets to be sent immediately (and individually) but even when setting socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) before socket.send(...), packets are still being received by the client (using socket.recv(1024)) in multiples.

Upvotes: 0

Views: 751

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123380

Disabling the Nagle algorithm only makes sure that writing data does not get delayed at the sender side. It does not prevent accumulation of the payloads of multiple packets on the recipients side. A recv(1024) will try to get up to 1024 bytes from the read buffer and it does not care if these bytes were send within a single or within multiple packets.

In general, TCP is a byte stream and has no implicit message semantics. This does not change by invoking some socket options, it still has to be treated as a byte stream. Any message semantics you want to have must be implemented in the application on top of this byte stream.

Upvotes: 2

Related Questions