MTU and splitting chunks

Within the standard and async-std libraries, if we look at TCP layer, is data automatically split if the size in bytes of the input is larger than the MTU? E.g., if the MTU is 1500 bytes, and you insert 3200 bytes, then does the TCP layer split it into 3 packets of 1500 + 1500 + 200 (not including headers)? Or, is this process something the higher-level user must keep in mind?

you need never worry about the MTU when writing software that uses TCP, the abstraction offered from the kernel is a stream, where any amount of bytes can be read and written and lower-level network details are handled internally

1 Like

Awesome! How about UDP?

well, UDP is different, it is packet-based so no automatic splitting will happen either on send or receive (it would be bad because packet boundaries can be important to the protocol!), that's all up to the application

on the other hand UDP packets are distinct from IP packets, and IP fragmentation/reassembly can happen when the UDP packet is larger than the MTU of the transport, this is out of control of the application

so you still don't really have to deal with the MTU, UDP packets can be pretty large, though AFAIK for performance reasons it's ill-advised to use larger packets than fit in common MTUs