有可能在java中为任何客户端程序选择临时端口号吗?



当任何客户端程序与服务器通信时,客户端使用临时端口号在服务器端口上与服务器通信。在Java中有没有办法控制/选择客户端临时端口号?

是,您指定本地地址/端口号:

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插座28 java.net.inetaddress %, % 20 int, int % 20 java.net.inetaddress % 20 % 29日

最新更新