I read following statement in the Socket tutorial.
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.
Below are my questions:
ServerSocket) by specifying a port, lets say 8001, now my server will start listening to requests on this port, now it gets a request from a client, something like http://abc:8001/test, so once it accepts the connection it will create a local port lets say 10001, so now this client request will be entertained over 10001 (or in other words connection with client would be established over port 10001) while 8001 will again be free and listening for new requests?ServerSocket will never be used for establishing connections?Please feel free to detailed light on the concepts of these questions, this will not only help me but also future visitors.
Does
ServerSocketcreate a new socket for every connection?
Yes.
I open a socket (ServerSocket) by specifying a port, lets say 8001, now my server will start listening to requests on this port, now it gets a request from a client, something like http://abc:8001/test, so once it accepts the connection it will create a local port lets say 10001,
No.
so now this client request will be entertained over 10001
No.
(or in other words connection with client would be established over port 10001)
No.
while 8001 will again be free and listening for new requests?
Yes.
So, does it means that original port I specified with ServerSocket will never be used for establishing connections?
No.
So, does it mean that if I having a connection with a client, let say over port 9001, then there can never be one more communication happening (or in other words connection established) on the same 9001 port until the original request I am catering is completed?
No.
The accepted socket uses the same local port as the listening socket, exactly as per the text you quoted.
You are confusing new sockets, as per your title, with new ports, as per the body of your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With