简体   繁体   English

如何使用公共 IP 访问连接到 Android 设备 wifi 热点的计算机上运行的 NodeJs HTTP 服务器?

[英]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.

相关问题 如何从连接在同一网络中的任何其他计算机或移动设备访问由 npm 运行服务器命令运行的 vue 项目? - How can I access vue project which is running by npm run server command from any other computer or mobile that is connected in the same network? 从 android 设备向 PC 上的 nodejs 本地服务器发送 http 请求 - sending http requests from android device to nodejs local server on PC 如何访问在同一个 Pod 中运行的 NodeJS 服务器? - How to access NodeJS server that is running in the same pod? NodeJS HTTP Server - 如何验证客户端的IP和登录? - NodeJS HTTP Server - How To Verify Client's IP and Login? tinylr / nodejs-如何访问当前运行的服务器 - tinylr/nodejs - how to access the currently running server 如何获得 HTTP 请求发送者的公共 IP? NodeJS(快递) - How can I get the public IP of the sender of a HTTP request ? NodeJS (express) Nodejs区分http请求; 多个具有相同公共 IP 的设备 - Nodejs distinguishing http requests; multiple devices with same public IP NodeJS-在两个IP地址上运行服务器应用 - NodeJS - Running server app on two IP addresses 如何使用 AWS EC2 公共 IP 部署 NodeJS 服务器应用程序? - How to deploy NodeJS Server app using AWS EC2 public IP? 如何在CentOS上运行的Apache HTTP服务器上设置Loopback NodeJS后端 - How to set a Loopback nodeJS backend on Apache HTTP server running on CentOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM