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.x.x to 192.168.y.y ip addresses.
What should I 开发者_如何学Cdo if I want to use the application over internet, from a remote machine, not local. For example which ip addresses should I use if my friend who lives another country wants to access my application.
On the server end, the easiest way is to bind to all available addresses by using IPAddress.Any
as the address. You'll need to give the client your public Internet address to connect to. 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.
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.
For instance, you can configure your router rules to point all port 80 requests to your 192.168.x.x machine, so that when ever a request for port 80 comes in, it automatically gets sent to a specific address on your subnet.
Your outgoing IP address. Use this site to see it: 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). 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).
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). This is called port forwarding.
精彩评论