且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

让我的客户端服务器应用程序通过Internet工作?

更新时间:2021-12-31 00:45:06

您无法对代码进行任何操作,而这完全与网络路由有关.

服务器绑定到正在运行的计算机的本地IP地址,然后您需要将端口转发规则放入该计算机与您要使用的端口的Internet(公共IP或ISP分配的IP)之间的任何调制解调器/路由器/防火墙中用于将任何连接请求路由到服务器计算机.如何做到这一点取决于硬件,因为制造商之间会有所不同.

客户端组件连接到您的朋友网络的公共IP,只要您正确设置端口转发规则,连接请求就会路由到服务器.
There is nothing you can do to your code to do this it is all about network routing.

The server binds to the local IP address of the computer it is running on, you then need to put port forwarding rules into any modem/routers/firewalls between that computer and the internet (public IP or ISP assigned IP) for the port you are using to route any connection requests to the server computer. How you do this in dependent on the hardware as it differs between manufacturers.

The client component connects to the public IP of your friends network and so long as you set-up the port forwarding rules correctly the connection request will be routed to the server.