I am developing a gaming server using the Winsock2 API from Windows, just for now until porting it to Linux.
The main problem I have found is that I don’t know how to differentiate gaming clients that come from the same router/network. Let´s imagine 2 gamers that are in the same network going to the Internet through the same router IP and port with, for example IP 220.100.100.100 and port 5000, how can my C/C++ server differentiate both TCP connections and know that they are two different gamers?
Can I find any difference in the sockaddr_in struct that returns the socket when accept(…) returns ??
If the two clients (gamers) are behind a router, it is hard to differentiate them just using sockets.
If you are using TCP then it shouldn’t be a problem. Each client connects over a unique socket so you know anything coming in on that socket is from them. When they first log on, I assume they supply some credentials (name, password) so just associate the credentials with the socket.
If you are using a connectionless protocol, like UDP, the first time they contact you, you give them a unique number or token. Next time they contact you, they must include their token in the message, so that you can identify them.
Am I missing something?