首页 > 解决方案 > 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

http://localhost:7000/users=mandar?lights=OFF

or

http://192.168.43.248:7000/users=mandar?lights=OFF

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:

http://(IP_address):7000/users=mandar?lights=OFF

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.

标签: node.jsnetworkingwebbrowserip

解决方案


你必须做端口转发。

您从谷歌搜索获得的 IP 地址是路由器的外向 IP 地址。但是,您的路由器通过您的本地 IP 地址(即 192.168.xy)了解您的计算机。

您必须将路由器配置为将来自互联网的数据包发送到端口 7000(或任何其他端口)到您计算机的端口 7000。

查看路由器关于端口转发的文档。路由器的 Web 界面上可能有一个设置页面,您可以进行所需的端口转发。配置好路由器后,网上有几个工具可以测试端口转发是否真的有效。我建议您在测试项目之前使用其中一种工具来验证配置。

您可能还想检查您的路由器是否有防火墙。您可以向防火墙添加例外,以便可以从 Internet 访问特定端口号。


推荐阅读