i have a java game app that uses sockets to communicate with each other.
the issue is when i do a socket listen (server), i can run another instance of the game on the same machine using the same port as before to listen, and it results in listening again. now i have two instances of the application both listening on the same port. you can imagine only one connects when a connection comes through.
the question is: how do i prevent the app from listening on the same port as another instance is already listening to?
thanks in advance.
EDIT: serverSocket = new ServerSocket(serverPort, backlog); im using this. should i try to use: ServerSocket(int port, int backlog, InetAddress bindAddr) instead?
EDIT: SOLVED! i did not handle the exception only trapped it. now it is working well. thanks for your inputs.
It’s not possible for two applications to listen to the same port with the same IP. The second application will get an Exception “port already in use”.