可以为java中的任何客户端程序选择临时端口号吗

可以为java中的任何客户端程序选择临时端口号吗,java,sockets,client-server,port,client-side,Java,Sockets,Client Server,Port,Client Side,当任何客户端程序与服务器通信时,客户端使用临时端口号在服务器端口上与服务器通信。是否有任何方法可以控制/选择Java中的客户端临时端口号。是的,您可以指定本地地址/端口号: Socket(InetAddress address, int port, InetAddress localAddr, int localPort) Creates a socket and connects it to the specified remote address on the specified

当任何客户端程序与服务器通信时,客户端使用临时端口号在服务器端口上与服务器通信。是否有任何方法可以控制/选择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.

@Pavan,localAddress是您的本地接口的地址(如果您不介意,请使用null)。它是否指定了我有两张网卡,要使用哪张网卡?我如何保留此本地端口。在Linux中,我想我需要更新ip_local_Reserved_ports文件。在windows中如何处理这个问题?从防火墙开始,我需要编写这个固定的本地端口规则,并且认为学习它会很好