How the clients (client sockets) are identified?
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-03-13T18:28:28Z
Indexed on
2010/03/13
18:45 UTC
Read the original article
Hit count: 143
To my understanding by serverSocket = new ServerSocket(portNumber)
we create an object which potentially can "listen" to the indicated port. By clientSocket = serverSocket.accept()
we force the server socket to "listen" to its port and to "accept" a connection from any client which tries to connect to the server through the port associated with the server. When I say "client tries to connect to the server" I mean that client program executes "nameSocket = new Socket(serverIP,serverPort)".
If client is trying to connect to the server, the server "accepts" this client (i.e. creates a "client socket" associated with this client).
If a new client tries to connect to the server, the server creates another client socket (associated with the new client). But how the server knows if it is a "new" client or an "old" one which has already its socket? Or, in other words, how the clients are identified? By their IP? By their IP and port? By some "signatures"?
What happens if an "old" client tries to use Socket(serverIP,serverIP) again? Will server create the second socket associated with this client?
© Stack Overflow or respective owner