I have to write a program using UDP sockets and I'm having trouble understanding what should I do in a scenario I have.
I have a server and a client. The server receives datagrams on an INADDR_ANY socket and for each unique client that shows up, it will sendto() a lot of information to. Each client also sends data periodically to the server.
For each client that contacts the listening socket, lets call it 0, I create a separate socket for, so I can send data to it without clogging socket 0. What I want to do is move all communication with a specific client to the new socket. Can I do that? The goal is to make the communication easier, efficient and avoid clogging any sockets.
So questions I failed to find answers for are:
- can I recv data from that socket from that specific client?
- If not, won't having all the clients write to socket 0 clog it if I won't do recvfrom often enough?
- If it's possible to recv data from a specific client on a separate socket, will that data come to BOTH socket 0 and the specific socket?
I know that TCP would work better for this but I have to use UDP. How should I do this? Is there an accepted "standard" of handling such situations?
Comment: I have a feeling I am misunderstanding UDP sockets but there's really very little tutorials on it when compared to TCP.