node.js - how to connect to a server running on computer using computer's IP address?
问题描述
I am working on IOT project in which I have to change some variables(fans speed, lights, etc). So just as a starter, I created a node.js server and tried to send requests to the server through a local network using local IP as
or
and it works fine.
Now I want to do the same over the internet. So I got Computer's IP address from https://www.google.co.in/search?q=myip and tried to send a request to the following URL:
This time it keeps on loading and finally shows this site can't be loaded. So what is the right way to connect to the server through the internet? Thank you.
解决方案
你必须做端口转发。
您从谷歌搜索获得的 IP 地址是路由器的外向 IP 地址。但是,您的路由器通过您的本地 IP 地址(即 192.168.xy)了解您的计算机。
您必须将路由器配置为将来自互联网的数据包发送到端口 7000(或任何其他端口)到您计算机的端口 7000。
查看路由器关于端口转发的文档。路由器的 Web 界面上可能有一个设置页面,您可以进行所需的端口转发。配置好路由器后,网上有几个工具可以测试端口转发是否真的有效。我建议您在测试项目之前使用其中一种工具来验证配置。
您可能还想检查您的路由器是否有防火墙。您可以向防火墙添加例外,以便可以从 Internet 访问特定端口号。
推荐阅读
- javascript - 在 Cordova 应用程序中获取动态创建的 html 行的文本
- qt - 区分动态分配的属性和静态分配的属性
- html - 如何更改div位置
- android - 从实时数据库中的已知子关键节点检索未知父节点
- typescript - 将 Typescript 路径指向项目文件夹之外的文件夹,以便可以在项目之间共享
- c++ - 为什么 QT Creator Preview 与我实际得到的不同?
- python - 如何将包含自定义格式定义的消息与 Protocol Buffers for Python 一起使用
- realex-payments-api - realex payment 我收到了回复,但如何以格式化的方式显示
- javascript - 如何在 Google 应用脚本中运行触发器而无需每次都重新验证
- networking - 为什么 Ansible 在 stdout 条件下没有失败这个字符串?