Java ServerSocket Multiple Listen Instances
Posted
by ikurtz
on Stack Overflow
See other posts from Stack Overflow
or by ikurtz
Published on 2010-05-16T16:19:32Z
Indexed on
2010/05/16
16:40 UTC
Read the original article
Hit count: 398
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.
© Stack Overflow or respective owner