1
votes

Suppose I have a server with multiple clients (UDP). Whenever it receives a packet from a client, the server will spend 1 second processing the packet and send out that a new packet to all clients immediately after processing.

Will the server be able to do this if 10 packets arrive within 0.1 seconds? In other words, is it able to send out a new packet to each client immediately after processing the first received packet? (I have the feeling that the socket would get "clogged" up by the 9 other unread packets)

The server loop would be like:

while (1) {
    read_a_packet()
    process_packet()
    send_new_packet_to_all_clients()
}
2

2 Answers

1
votes

Incoming UDP packets are put into buffer for future retrieval. If your processing is slow enough to fill the socket buffer with packets, following packets will just be discarded.

See also How does a Linux socket buffer overflow? and C++ UDP sockets packet queuing (also check out comments there).

0
votes

By your own definition, process_packet() takes 1 second to run. A thread can only do one thing at a time, so such a looping server in a single thread will take 10 seconds to process 10 packets. So either speed up process_packet() to less then 1 second, or else run multiple processing threads so you can process multiple packets in parallel.