UDP packets

Started by
2 comments, last by AndersO 22 years, 5 months ago
Hi all. I thought I read somewhere that if a UDP packet is received, its allways complete. Unlike TCP, if you send a 100 bytes in a single call to send(), the receiving side might need to call recv() several times to get the whole 100 bytes data. So UDP packets preserves the packet boundry, true?. Cant find out where I read this, was I dreaming?. Cheers
Advertisement
Yes, well, sorta. UDP is packet based meaning that it is sent in small bundles of data. TCP does this too but it has an extra layer of abstraction to make it streamable. UDPs that are sent will be recv''ed at the same size assuming its smaller than the MTU (or maximum transmission unit) which is usually around 512 but changes. Also note that because of this you might want to avoid sending small fragments of data as sending packets sized 12, 16, 20 and 20 bytes will be slower than sending it all in one datagram.
CorsairK8@Fnemesis.comLinux Debian/GNU RulezThis is my signitory!C Is Tha Best!
Or to say it more concretely...

Yes, if you''re using UDP and you send() 100 bytes in a single call then when you do a recv() you''ll get all 100 bytes (and no others) on the other side. In TCP a send() of 100 bytes might be recv()''d one byte at a time, or 5, or all 100, or all 100 plus the first couple of bytes of the next send(), you can''t tell.

You shouldn''t choose UDP or TCP just because of this though. They are very different beasts.

-Mike
-Mike
Thanks, thats what I needed to know!



This topic is closed to new replies.

Advertisement