• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

multi sockets on one port

every time I assign more than one socket on a single port the code compiles ok but it throws bind exceptions when I run the server.How can I overcome this ???
1 Solution
is it even possible to assign more than one socket to a single port? I thought each port could only handle one socket?
spunog, you can not listen more than once on a port. Why do you need to listen more than once? Can you paste a piece of you code here?
Are you trying to set up a ServerSocket or a Socket?

A server socket isn't an actual open connection to another computer, it's an open port waiting on your local machine.  If you call the accept() method on a ServerSocket, it will wait until someone connects to that port.  At that point, it returns a Socket object, which is a real live connected socket.  You can call serversocket.accept() over and over again, getting as many Sockets as you want.  (as long as people keep connecting)
spunogAuthor Commented:
So I just put this line in once ,
ServerSocket socket = new ServerSocket(6666, 300);
and have as many of these as I see fit for example
Socket s = socket.accept();    
Socket s1 = socket.accept();    
Socket s2 = socket.accept();    

spunogAuthor Commented:
Fair play newcumbd,
that has worked fine
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now