简体   繁体   English

Web服务器的UDP打孔?

[英]UDP punch hole for a web-server?

For my academic project, I am trying to achieve this. 对于我的学术项目,我正在努力实现这一目标。 A web server node JS application listening on port 3000. So If you curl http://localhost:3000 you will get Hello World! 一个在端口3000上侦听的Web服务器节点JS应用程序。因此,如果curl http://localhost:3000您将获得Hello World! . ( A simple web page. (一个简单的网页。

Now I am running above webserver in my local machine. 现在,我在本地计算机上的网络服务器上方运行。 And my modem is behind NAT. 我的调制解调器位于NAT之后。 Suppose If I port forward in the modem to myip:3000 then it is open to the world. 假设如果我将调制解调器中的端口转发到myip:3000那么它将对世界开放。 But here is the biggest thing I am stuck - I don't want to use the modem for port forwarding, instead, I will use third party server for UDP Punch Hole. 但是,这是我最大的困难-我不想使用调制解调器进行端口转发,而是将第三方服务器用于UDP Punch Hole。

Now my requirement is anyone from net should able to access my webserver at curl http://third-party-server-ip:3000 . 现在,我的要求是,任何来自net的人都应该能够通过curl http://third-party-server-ip:3000访问我的Web curl http://third-party-server-ip:3000

What I am trying is to write another client - which opens a connection to the third party server. 我正在尝试编写另一个客户端-这将打开与第三方服务器的连接。 Say it did a hole punching at port 41234 . 说它在端口41234打孔。 That port is open. 该端口是开放的。 The third-party host can send something to that port. 第三方主机可以向该端口发送内容。

Now anyone in the internet initiate this command curl http://third-party-ip:3000 to the third party host. 现在,互联网上的任何人都可以向第三方主机发起以下命令curl http://third-party-ip:3000 So the third party returns the myip:udpPunchHolePort ie, myip:41234 . 因此,第三方返回myip:udpPunchHolePortmyip:41234

anyone will again curl to myip:41234 it will be received by the node js UDP punch app, so it will redirect to localhost:3000 . 任何人都将再次卷曲到myip:41234 ,它将被节点js UDP打孔应用程序接收,因此它将重定向到localhost:3000 Finally, the anyone will receive the response from localhost:3000 . 最后, anyone都会收到localhost:3000的响应。

My two questions - 我的两个问题-

  1. Is there any better way than the one I proposed here? 有没有比我在这里建议的方法更好的方法?
  2. Is there any well-known node-js lib for this kind of stuff, I see, I can use UDP punch hole . 我有没有众所周知的node-js lib这样的东西,我可以使用UDP打孔 Or I am thinking to write a Lib to do this in general - does this sounds like re-inventing the wheel? 或者我正在考虑编写一个Lib来总体上做到这一点-听起来像是在重新发明轮子吗?

Note - In this academic project, we are trying to learn how to make any local application open to the world without port forwarding in the modem. 注意-在此学术项目中,我们正在尝试学习如何使任何本地应用程序对世界开放,而无需在调制解调器中进行端口转发。

We read on skype protocol analysis , that is also our inspiration. 我们阅读了Skype协议分析 ,这也是我们的灵感。

请求流程

No, that won't work. 不,那行不通。

  1. HTTP runs over TCP, not UDP. HTTP通过TCP而不是UDP运行。 Punching a UDP hole doesn't do you any good -- any TCP connection to the backend HTTP server will still fail. 刺破UDP漏洞对您没有任何好处-与后端HTTP服务器的任何TCP连接仍将失败。

  2. HTTP redirects are not magic. HTTP重定向不是魔术。 If a user cannot access a specific host:port, redirecting them to a URL on that host:port will just make their browser time out when it requests that URL. 如果用户无法访问特定的host:port,则将其重定向到该host:port上的URL只会使他们的浏览器在请求该URL时超时。

  3. You cannot send a response from a different host:port from what the browser requested, because there is no TCP connection established with that endpoint. 您无法从浏览器请求的主机,端口发送响应,因为没有与该端点建立TCP连接。

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

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