When any client program communicates with server client uses an ephemeral port number to communi开发者_如何学Gocate with the server on server port. Is there any way to control/Select the client ephemeral port number in Java.
Yes, you specify the local address / portnumber:
Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
Creates a socket and connects it to the specified remote address on the specified remote port.
http://download.oracle.com/javase/6/docs/api/java/net/Socket.html#Socket%28java.net.InetAddress,%20int,%20java.net.InetAddress,%20int%29
精彩评论