I currently have a server that runs a game where each client controls a player. I have decided to use UDP because it does not wait for the client to receive the packet and therefore can run smoothly. I would like to assign each client a player, and the only way I believe I can do that is to assign each client a number based on the number of clients that had joined before them. That way, every time a client sends a packet I could identify which client they were and act accordingly.
However, UDP is not a connection-based method of communication, as it sends packets and hopes that someone on the same port is listening. I do not want to identify clients by IP number, for I test my application by running multiple clients on one computer that also holds the server.
So my question is: How does one find out how many clients are listening on a port? Or if that isn't possible, how does one distinguish one client from another and identify them through a number such as 1, 2, 3 or 4? I have not included any code because my current UDP server and client would be of no use, and this is a question about something I have no idea how to do.
Any help would be appreciated.