Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这在Java中是不可能的吗?DatagramSocket.bind 方法必须采用 NULL 或 IP:PORT。您不能只传递描述 NIC 的 IP,然后自动选择 PORT。除非我遗漏了一些东西,否则这没有任何意义。
使用DatagramSocket. 这将绑定到任何端口。您不必使用 bind 方法。
DatagramSocket
只需将端口号指定为零,或者按照 Mike Q 的建议省略它。在这两种情况下,系统都会为您分配一个端口。