Let's first describe some basics:
Each socket has a receive and send buffer. When the network equipment signals the arrival of a new packet and the receive buffer is full, the packet is discarded. Buffer sizes are controlled using the SO_RCVBUF and SO_SNDBUF socket options, see setsockopt(3) . The OS sets some default values ββ(and there is the /etc/sysctl.conf file). This is in the BSD system:
~ $ sysctl -a | grep space
net.inet.tcp.recvspace = 16384
net.inet.tcp.sendspace = 16384
net.inet.udp.recvspace = 41600
net.inet.udp.sendspace = 9216
The difference between TCP and UDP is that the former takes care of the data sequence and retransmission of the dropped packets, as well as the flow control (a slow reader slows down the fast script), and the latter does not.
So yes, using UDP to transfer files is not the best, but workable option. You just need to invent a part of TCP and weigh the overhead of re-inventing against one of TCP. In addition, the general wisdom is that UDP is best suited for applications that may suffer some reordering / packet loss (e.g., audio / video streams).
Then there is an erroneous idea that each socket needs a separate stream to send / receive data, which is far from the truth. Many excellent high-performance network applications were written without threads, but using non-blocking sockets and some polling mechanism (see select(2) , poll(2) , epoll(7) ).
To the question itself:
Yes, the kernel can drop packets if the application is too busy to have enough free space in the socket receive buffers. But since each socket has its own, separating control and data flows might help. Personally, although I would go for a simple TCP server setup - listen on the port, accept the connection on one client, implement a meaningful protocol on top of the TCP stream. I agree that playing with UDP and low-level protocol machines is a lot of fun, but it has already been done and decades of research have gone into tuning TCP performance. What matters at the end of the day is the reliability (first) and performance (second) of your application.
Hope this helps.
source share