简体   繁体   中英

Why doesn't error occur in UDP socket communication?

I am a student studying computer networking. I made very simple server-client socket communication program in C on Ubuntu, using UDP protocol. I read in the book that UDP is unreliable data transferring protocol while TCP is reliable data transferring protocol. The reason is that UDP is just sending packets while TCP is sending and waiting for receiving corresponding ack message.

Anyhow, I tried many times to send an image file (around 1Mb) from client to server using UDP socket. However, the image file was transmitted successfully without any one failure.

Does socket library have error correction scheme although UDP setting?

ps) My program is almost the same as the common echo socket code in C. Just different thing is not echoing but copying. That is, client transfers data and server receives and copies it.

For reference) I used sys/socket header for socket functions. I used fopen, fread and fwrite for copying file.

Anyhow, I tried many times to send an image file (around 1Mb) from client to server using UDP socket. However, the image file was transmitted successfully without any one failure.

If done on a single host via loopback no packet will be lost (except if you enable some packet loss testing function). That is because modern OSs' network layer only passes around pointers to packet descriptors. So when you do a send() or write() on a socket a packet descriptor struct is constructed around your data; that struct kind of "lives" in the writing process and only a pointer to it is passed to whoever is going to receive it. If it's another process this results effectively in IPC (and if you use the right socket operations this goes even as far as a zero-copy data transfer). Only if that packet descriptor ends up within a network interface driver, more than just that pointer will be passed around.

On a local network it's also next to impossible to loose a packet, because collision detection happens on the link layer and modern switches are store and forward architectures. It takes a huge amount of network load for noticing any form of packet loss back pressure.

For packet loss to become noticeable you must either use a highly contended shared medium network (say, W-LAN with a lot of clients contending for it) or go through at least one router close to its bandwidth capacity.

Does socket library have error correction scheme although UDP setting?

No.

There is no error correction in UDP. It is still unreliable, even though you succeeded many time to transfer a file using it.

The probability of error is very small in today's networks, especially in a LAN or on the same machine. That is, you may need to try sending a file millions of times before you get an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM