As far as I can see, the only way to distinguish multiple clients with the same IP using UDP is for each client to have a unique port. If you bind two clients with the same IP to the same port, you get random behavior determining which client gets packets. The problem is that I don't have a way of guaranteeing each individual process that is ran under the same IP receives a unique port.
It seems that Winsock already has a partial answer to this problem:
Binding to a specific port number other than port 0 is discouraged for client applications, since there is a danger of conflicting with another socket already using that port number on the local computer.
Source: http://msdn.microsoft.com/en-us/library/ms737550
The above may only apply to a single computer running on the same IP whereas I need unique ports for all computers using the same IP.
UPnP is quite a mystery to me, but it may have the true answer to this problem. So, I'll be checking out the
MiniUPnP library referenced
here.
Conclusively, I just need two instances of the same application running on the same IP to be guaranteed to be able to receive packets. Is there a way to do this in SFML?
Edit:After posting, I realized that I can use a temporary port to request a unique port from the server. With the unique port that the server gives, I can rebind the client to a permanent port.
However, this is just a hack. Two clients on the same IP will not be able to connect at the same time because the temporary port is the same.