the packet size of using socket

I have a question about socket programming. When I use socket to send the data, we can use the API such as sendto() to send using TCP or UDP.
For sendto(), we give a array pointer and the byte number we want to send.

In this case, if once I gave a large byte number (e.g.: 20000 bytes), based on my understanding, MTU of the network will not be that big so socket actually send mutiple packets instead of one big packet. Since these 20000 bytes are split into several UDP/TCP packets, is this process UDP/TCP fragmentation ?

My another question is what the size I should put into sendto(), then I can gurantee call sendto() once, socket only sends one TCP/UDP packet?

Thanks in advance.
The fragemtation depends on the underlying hardware on the sender and receiver side. Thus The hardware is responsible for fragmentation/defragmentation controlled by the protocoll.

So I would think it is actually easier to let the hardware do its job. Otherwise you need to implement a fragmentation/defragmentation logic yourself.

For UDP the packets shouldn't be too big otherwise they might get lost (for some reason).
Topic archived. No new replies allowed.