I am trying to do a client/server setup and naturally I had to choose a port for each of them. The server one has been fine but the client one has given me trouble on several occasions. I get the exception:
SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted.
I understand that the port has been taken, but every time I end up googling the port I was using I end up finding some obscure thing that happened to be running while trying to run my game. Rather than trying new random ports every time this happens, is there a sure way to find myself a port that won't be used for anything? Any of the lists I can find of used ports always seem to show my ports as unassigned.
Alternatively, would it be a good idea to, in code, try a random port until I get one that works?