Elvis Sikora Elvis Sikora - 24 days ago 7
HTTP Question

How can I accept requests from anyone on the Internet?

I have a simple HTTP server implemented on Node, though I have tried to do the same thing with other languages and could not figure out how to.

I can pick some port on

localhost
, say,
1337
, and respond to requests just fine on my machine. I then want to access the server from the browser on my smartphone. Leaving it listening on
localhost
doesn't work (which is just as I expect). Then I try either my own IP, which I get googling
my ip
, or
192.168.1.1
, which I understand refers to the LAN. I try these with several ports.

Both of those give errors indicating that these addresses cannot be bound.

Now, I suppose I am misunderstanding how networks and IP addresses work. How can I make this work? That is, how can I make my HTTP server accept requests from other hosts in the LAN, and then from anyone on the Internet?

Answer

For your local network, jump on the host computer and open your terminal. For windows, type ipconfig or for Unix, type ifconfig. Identify your computers IP here. You'll be able to connect from your phone now using this IP.

For anyone to connect, you need to port forward your router to the IP you just found. How to do this varies on the router model, you might need to Google for your specific router.