简体   繁体   English

从Internet连接到服务器插槽到通过LAN连接到Internet的系统

[英]Connecting to a serversocket from internet to a system connected to internet via LAN

I want to connect to a server which is connected to internet via LAN. 我想连接到通过LAN连接到Internet的服务器。 So in the client side i need to write code like new Socket("i dont know the ip",PORT_NO) Here which ip address should i give? 因此,在客户端,我需要编写类似新Socket(“ i do n't know the ip”,PORT_NO)的代码,在这里我应该给哪个IP地址? Its obvious that i can't give both LAN ip address as well as local address of the server. 很明显,我不能同时提供局域网IP地址和服务器的本地地址。

You server should be running on a machine with public IP. 您的服务器应在具有公共IP的计算机上运行。 You cannot give private IP ie address server got using DHCP when it is connected to LAN. 您不能提供专用IP,即地址服务器连接到LAN时使用DHCP。 You may need to do more configuration on your router to get the packet to your listening java server. 您可能需要在路由器上进行更多配置,才能将数据包发送到正在侦听的Java服务器。

您将需要提供您的LAN ip地址,因为每个设备的localhost ip都是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM