Dstributed Erlang, networking, echo server

给你一囗甜甜゛ 提交于 2019-12-09 01:28:27

If your friend is trying to connect to you over the internet, the answer is no, you cannot simply give him your IP address and have him able to connect.

The reason is because of NAT, or Network Address Translation. Most computers are not connected directly to the internet, but go through a router first. The router gives your computer a local IP address, typically starting with 192.168 or 10. When you ask a service on the internet what your IP is, it will report to you the internet facing address of your router, not the machine you are browsing from.

        IP seen from upstream
YOU     10.x.x.x
 |
Router  81.157.x.x
 |
Internet

This means that when someone tries to connect to your telnet server with your external IP address, the request arrives at your router, which doesn't know what to do with it. The connection is then rejected.

Internet -> 81.157.x.x:8888 -> Router -> ?

The way to get around this is call Port Forwarding. This is a configuration option on the router which will forward the request for a given port to an IP address on the local network. You can find the address by checking the network configuration locally on your own machine. Don't use an online website, as that will give you the router's public IP address instead:

Internet -> 81.157.x.x:8888 -> Router -> 10.x.x.x:8888 -> You

Note that if you don't have control over your network, e.g. you are at school or work, you need a network admin to do this. Unless it's for something really important, they probably won't want to set it up. Opening the network like this can be dangerous if you allow access to a sensitive port, such as ssh(22). Also, corporate networks are often much more complex than home networks, so setting this up is a major hassle.

If you are both on the same local network, such as connected to the same university or work network, you should be able to connect to the IP given from the local config (such as ifconfig), not the IP from Google.

A work around, if you're just testing with your friend, is to use a VPN, or Virtual Private Network. A free solution is available from LogMeIn called Hamachi. Both you and your friend need to download and install this app. One you should create a private network, and have the other person join. Make sure your echo server is listening on 0.0.0.0, which means on all IP addresses. Then the client should be able to connect to the server via the Hamachi IP of the server.

The VPN solution should work even if you can't control your own network configuration. It's safer than setting up port forwarding, since only people in your VPN can access your ports.

One last note, make sure your local firewall is disabled, or at least allowing your app and port 8888 through.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!