I'm sending many TCP packets each of size 50 bytes over the network. Later I found it out TCP aggregates a few 50 byte packets into a single TCP packet. My question is, is there a way to avoid TCP aggregation in 'C' program?
Packing multiple sent packets into a single TCP packet is handled using an algorithm known as Nagle's algorithm. To disable it, set the TCP_NODELAY option on your socket:
int flag = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
Note that this decreases the efficiency of your network, and should be avoided unless you really do need each packet to be sent immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With