1

I've seen this post

http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html

since it wrote:

If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.

So are there multiple server sockets which has the same port in the server side?

Alexis
  • 1,080
  • 3
  • 21
  • 44
  • 2
    http://stackoverflow.com/questions/489036/how-does-the-socket-api-accept-function-work – Sotirios Delimanolis Dec 19 '13 at 14:31
  • Yes, the server uses one predefined port number. Clients are probably using dynamic ports. The unique identifier for the socket is the clients IP and port number (in combination of the server socket of course). – qstebom Dec 19 '13 at 14:38

1 Answers1

4

There is one ServerSocket. It accepts incoming connections through the accept() method. This returns a Socket which you use on the server side to handle the connection to a particular client.

Toon Borgers
  • 3,638
  • 1
  • 14
  • 22
  • 1
    also: that ServerSocket (internally) typically maintains a queue of listeners to handle the case where multiple connections arrive right after one another. The default is typically something like 50, so frequently you don't need to mess with it, but one of the ServerSocket constructors (http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html#ServerSocket(int,%20int)) will accept a parameter to let you increase that. – JVMATL Dec 19 '13 at 14:38
  • @JVMATL It doesn't maintain a 'queue of listeners'. It maintains, in the kernel, a backlog queue of already completed inbound connections. – user207421 Jan 19 '16 at 01:29