[英]How to access a NodeJs HTTP Server running on a computer connected to wifi hot-spot of Android device with public IP?
Android device ( Internet Connected )
|
(Wi-Fi Hot-spot)
|
|
Computer ( NodeJs Server started )
The NodeJs server starts only with private IP... NodeJs 服务器仅以私有 IP 启动...
How to start the NodeJs server with the public IP ?如何使用公共 IP启动 NodeJs 服务器?
The NodeJs server started in the computer: ( No public IP is listed )计算机中启动的NodeJs服务器:(未列出公共IP )
C:\Users\ASUS>http-server .
Starting up http-server, serving .
Available on:
http://192.168.42.74:8080
http://192.168.137.1:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server
[ However, if I start the server in my Android device (using Termux), I get the public IP... ] [但是,如果我在我的 Android 设备中启动服务器(使用 Termux),我会得到公共 IP... ]
Wow, that's an interesting question.哇,这是一个有趣的问题。 If you want to use your server inside your LAN you can do so by simply entering the IP address and port number of your server.如果您想在 LAN 中使用您的服务器,您只需输入服务器的 IP 地址和端口号即可。 The server could be your mobile or computer.服务器可以是您的手机或计算机。 In the case of mobile hotspot, you can access it using its default gateway IP which is by default 192.168.43.1.对于移动热点,您可以使用其默认网关 IP 访问它,默认网关为 192.168.43.1。 Here you can check I gave its demonstration, where mobile hotspot was used as a server for all devices in LAN.在这里你可以查看我给出的演示,其中移动热点被用作局域网中所有设备的服务器。
The tricky part is when you try to access your server from the internet.棘手的部分是当您尝试从 Internet 访问您的服务器时。 Obviously, when you connect to the internet, a public IP is given to your router (or mobile) by ISP.显然,当您连接到互联网时,ISP 会为您的路由器(或移动设备)提供一个公共 IP。 Any data coming inside or going outside of LAN uses this public IP.任何传入或传出 LAN 的数据都使用此公共 IP。 One of the reasons to allocate one public IP is to hide the IP of LAN devices for which the router performs NAT.分配一个公共 IP 的原因之一是隐藏路由器对其执行 NAT 的 LAN 设备的 IP。
You can configure your router to redirect incoming traffic to a particular device in LAN which will be running NodeJs server.您可以将路由器配置为将传入流量重定向到 LAN 中将运行 NodeJs 服务器的特定设备。 For which, I think, you can do port forwarding.我认为,您可以为此进行端口转发。 Check the answer here .在这里检查答案。 Do remember that public IP is not static.请记住,公共 IP 不是 static。 ISP uses DHCP to dynamically allocate public IPs to its customers. ISP 使用 DHCP 为其客户动态分配公共 IP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.