billu billu - 6 months ago 10
Java Question

In TCP MultiThreaded Server, if a client gets service ,how to find the port number of servicing socket?

In TCP Multi Threaded Server, if a client gets service ,how to find the port number of servicing socket?

From sun java tutorials

When a connection is requested and successfully established, the accept method returns a new "Socket object" which is bound to the same local port and has it's remote address and remote port set to that of the client. The server can communicate with the client over this new Socket and continue to listen for client connection requests on the original ServerSocket

how can i find the port number of the "Socket object"?

Answer

Does Socket.getPort() not do what you want? Or do you mean you want the local port (again, there's Socket.getLocalPort()? If you could give a worked example of what you're after, it would be easier to understand.