简体   繁体   English

套接字通信C#-IP地址

[英]Socket Communication C#- IP Address

I have a socket application which I can use in local network, at home. 我有一个套接字应用程序,可以在家里的局域网中使用。 I can make them communicate for example from 192.168.xx to 192.168.yy ip addresses. 我可以让他们从192.168.xx到192.168.yy ip地址进行通信。

What should I do if I want to use the application over internet, from a remote machine, not local. 如果要通过Internet从远程计算机而不是本地计算机上使用该应用程序,该怎么办。 For example which ip addresses should I use if my friend who lives another country wants to access my application. 例如,如果居住在另一个国家的朋友想要访问我的应用程序,我应该使用哪个IP地址。

On the server end, the easiest way is to bind to all available addresses by using IPAddress.Any as the address. 在服务器端,最简单的方法是使用IPAddress.Any作为地址绑定到所有可用地址。 You'll need to give the client your public Internet address to connect to. 您需要为客户提供您的公共Internet地址以进行连接。 If you're being a NAT, it might involve looking at your router for the address (or using http://www.whatismyip.com/ ) and configuring it to route the traffic to your PC. 如果您正在使用NAT,则可能需要在路由器上查找地址(或使用http://www.whatismyip.com/ )并将其配置为将流量路由到PC。

You need to set up your router to forward the port that you wish to communicate on. 您需要设置路由器以转发您希望在其上进行通信的端口。 Once you have that in place, give your friend your public IP address. 设置好地址后,请为您的朋友提供您的公共IP地址。

For instance, you can configure your router rules to point all port 80 requests to your 192.168.xx machine, so that when ever a request for port 80 comes in, it automatically gets sent to a specific address on your subnet. 例如,您可以配置路由器规则,以将所有端口80请求都指向192.168.xx计算机,这样,一旦端口80请求进入,它就会自动发送到子网中的特定地址。

Your outgoing IP address. 您的外发IP地址。 Use this site to see it: http://www.whatismyip.com/ 使用此网站可以查看它: http : //www.whatismyip.com/

And of cause port forward your router. 并导致端口转发您的路由器。

You will have to use the IP address provided by you ISP (internet service provider). 您将必须使用ISP(互联网服务提供商)提供的IP地址。 Usually these IP addresses are non static, so that you need to provide some way to resolve your dynamic IP address to a static name (dyndns providers do this usually). 通常,这些IP地址是非静态的,因此您需要提供某种方式将动态IP地址解析为静态名称(dyndns提供程序通常会这样做)。

In addition you need to configure you router to forward the incomming traffic on port xxx to your local machine (this is usually not your router, except when you are using a modem). 另外,您需要配置路由器,以将端口xxx上的传入流量转发到本地计算机(除非使用调制解调器,否则通常不是路由器)。 This is called port forwarding. 这称为端口转发。

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

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