I am trying to create an iterative server based on datagram sockets (UDP). It causes a connection to the first client, which it receives from the first call to recvfrom () (yes, I know that this is not a real connection). After serving this client, I disconnect the UDP socket (calling connect with AF_UNSPEC), then I call recvfrom () to get the first packet from the next client.
Now the problem is that calling recvfrom () in the second iteration of the loop returns 0. My clients never send empty packets, so what could happen.
This is what I am doing (pseudo code):
s = socket(PF_INET, SOCK_DGRAM, 0)
bind(s)
for(;;)
{
recvfrom(s, header, &client_address) // get first packet from client
connect(s,client_address) // connect to this client
serve_client(s);
connect(s, AF_UNSPEC); // disconnect, ready to serve next client
}
EDIT: , .
, , ( ).