views:

36

answers:

1

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"?

+1  A: 

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.

Jon Skeet
i tried that , it poits to the serversocket port specified in the constructor!! but i want to know what is the port number of socket object created using serversocket.accept() method...thanks in advance!!!
billu
@billu: So you want the local port - did you try Socket.getLocalPort?
Jon Skeet
is the port number of serversocket object to listen for new client and socket object created to serve multiple clients in server program are the same ?
billu
@Billy: I'm afraid I don't follow you. The connected socket should have a fresh local port.
Jon Skeet