不看文档的人……public ServerSocket(int port) Creates a server socket, bound to the specified port. A port of 0 creates a socket on any free port. port设为0就自动拿一个空闲端口。 或者bind(null)也行。 public void bind(SocketAddress endpoint) throws IOExceptionBinds the ServerSocket to a specific address (IP address and port number). If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.
Creates a server socket, bound to the specified port. A port of 0 creates a socket on any free port.
port设为0就自动拿一个空闲端口。
或者bind(null)也行。
public void bind(SocketAddress endpoint)
throws IOExceptionBinds the ServerSocket to a specific address (IP address and port number).
If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.