开发者

Is it Possible to select the ephemeral port number for any CLient Program in java

开发者 https://www.devze.com 2023-03-19 16:59 出处:网络
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 epheme

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

0

精彩评论

暂无评论...
验证码 换一张
取 消