简体   繁体   English

分发Erlang,网络,echo服务器

[英]Dstributed Erlang, networking, echo server

so my year long project involves doing some pretty nasty stuff with Erlang. 所以我一年的项目涉及到使用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 我按照本指南中的代码http://20bits.com/article/network-programming-in-erlang ,为服务器提供Erlang代码以回显输入到其中的文本

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 运行它的说明是启动erlang代码,他推荐端口8888,然后telnet到localhost,然后访问echo服务器

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 我认为它应该像给他当前的IP地址一样容易,并使用它来远程登录,但它没有用

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 说实话,我不认为这是关于与erlang建立联系的正确研究方法,但大多数地方似乎都在讨论在本地运行的事情。

My ideal guide would be something that talks about using multiple Erlang nodes, with some kind of very basic client/network setup 我的理想指南将讨论使用多个Erlang节点,以及某种非常基本的客户端/网络设置

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. 如果你的朋友试图通过互联网连接到你,答案是否定的,你不能简单地给他你的IP地址,让他能够连接。

The reason is because of NAT, or Network Address Translation . 原因是NAT或网络地址转换 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地址,通常以192.168或10开头。当您在互联网上询问您的IP是什么时,它会向您报告您的路由器的面向互联网的地址,而不是您正在浏览的机器。

        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. 这意味着当有人尝试使用您的外部IP地址连接到您的telnet服务器时,请求会到达您的路由器,该路由器不知道如何处理它。 The connection is then rejected. 然后拒绝该连接。

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

The way to get around this is call Port Forwarding. 解决这个问题的方法是致电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. 这是路由器上的配置选项,它将给定端口的请求转发到本地网络上的IP地址。 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: 不要使用在线网站,因为这将为您提供路由器的公共IP地址:

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

Note that if you don't have control over your network, eg 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). 如果允许访问敏感端口(例如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. 如果您在同一个本地网络上,例如连接到同一所大学或工作网络,您应该能够连接到本地配置(例如ifconfig)提供的IP,而不是来自Google的IP。

A work around, if you're just testing with your friend, is to use a VPN, or Virtual Private Network . 如果您只是与您的朋友一起测试,解决方法是使用VPN或虚拟专用网络 A free solution is available from LogMeIn called Hamachi . LogMeIn提供免费解决方案, 名为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. 确保您的echo服务器正在侦听0.0.0.0,这意味着在所有IP地址上。 Then the client should be able to connect to the server via the Hamachi IP of the server. 然后客户端应该能够通过服务器的Hamachi IP连接到服务器。

The VPN solution should work even if you can't control your own network configuration. 即使您无法控制自己的网络配置,VPN解决方案也应该可以正常工作。 It's safer than setting up port forwarding, since only people in your VPN can access your ports. 它比设置端口转发更安全,因为只有VPN中的人才能访问您的端口。

One last note, make sure your local firewall is disabled, or at least allowing your app and port 8888 through. 最后一点,请确保您的本地防火墙已被禁用,或者至少允许您的应用和端口8888通过。

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

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