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.
我想连接到通过 LAN 连接到 Internet 的服务器。所以在客户端我需要编写像 new Socket("i dont know the ip",PORT_NO) 这样的代码,我应该在这里给出哪个 ip 地址?很明显,我不能同时提供 LAN ip 地址和服务器的本地地址。
您的服务器应该在具有公共 IP 的机器上运行。当连接到 LAN 时,您不能提供私有 IP,即使用 DHCP 获得的地址服务器。您可能需要在路由器上进行更多配置才能将数据包发送到您的侦听 Java 服务器。
您需要提供您的 LAN ip 地址,因为每个设备的 localhost ip 都是相同的。