简体   繁体   中英

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...
How to start the NodeJs server with the public IP ?

The NodeJs server started in the computer: ( No public IP is listed )

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

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. 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. 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. Obviously, when you connect to the internet, a public IP is given to your router (or mobile) by ISP. Any data coming inside or going outside of LAN uses this public IP. One of the reasons to allocate one public IP is to hide the IP of LAN devices for which the router performs NAT.

You can configure your router to redirect incoming traffic to a particular device in LAN which will be running NodeJs server. For which, I think, you can do port forwarding. Check the answer here . Do remember that public IP is not static. ISP uses DHCP to dynamically allocate public IPs to its customers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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