且构网

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

通过Internet上的TCP套接字发送/接收字节(可能使用静态IP)

更新时间:2023-11-09 12:21:52

一旦有了静态IP,就需要将其添加为网络适配器中的IP之一,请查看

Once you have the static IP you need to add it as one of the IP's in your network adapter, check out Setting a static IP guide for doing the same.

然后,您需要确保服务器套接字在此IP上列出,因为您正在使用IPAddress.Any,它将绑定到系统上所有可用的IP地址.

Then you need to make sure your server socket is listing on this IP, since you are using IPAddress.Any it will bind to all available IP addresses on your system.

最后,您需要在客户端代码中显式提供静态IP.可能将此IP存储在配置文件中,以便以后进行更改.如果愿意,可以设置一个自定义域名,然后将其指向用于使用它的静态IP而不是IP.

Finally you need to explicitly provide the static IP in your client code. Possibly store this IP in a configuration file for changing it at a later stage. If you prefer you can set a custom domain name and point it to the static ip for using it instead of the IP.