Dstributed Erlang, networking, echo server

偶尔善良 提交于 2020-01-14 03:03:08

问题


so my year long project involves doing some pretty nasty stuff with Erlang. I am just starting to get to grips with it. I have very limited knowledge of networking and need to ask how/why something doesn't work.

I followed the code from this guide, http://20bits.com/article/network-programming-in-erlang, that provides Erlang code for a server to echo back text that is fed into it

The instructions to run it is to start the erlang code, he reccomends port 8888, and then telnet to the localhost and voila, access to the echo server

My question is, would it be easy for me to run this server on my machine and have a friend telnet into the server?

I thought it owuld be as easy as giving him my current ip address and using that to telnet in, but it didnt work

To be honest, I dont think this is the right line of researching I should be doing with regards to networking with erlang, but most places seem to talk about things running locally

My ideal guide would be something that talks about using multiple Erlang nodes, with some kind of very basic client/network setup


回答1:


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.



来源:https://stackoverflow.com/questions/19668743/dstributed-erlang-networking-echo-server

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