Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect Device to Mac localhost Server? [closed]

How do I allow any device, e.g., iPhone, to connect over a WLAN to my Mac's localhost server?

On my Mac, I'm running a "Hello World" HTTP Node.js server that serves a page, which Safari opens successfully, at http://localhost:1337. And, running ipconfig getifaddr en1 in Terminal outputs 192.168.1.9.

But, Safari, on both iPhone & Mac, displays "Safari can't connect to the server" when it tries to open http://192.168.1.9:1337.

I don't think this should involve port forwarding because I only want the HTTP server to be available privately, not publicly.

Related:

  • Accessing localhost from iPhone (in same network)
  • https://superuser.com/questions/308451/connect-to-localhost-from-another-computer
  • https://superuser.com/questions/400752/can-we-run-local-server-over-local-network-without-internet-access
  • https://serverfault.com/questions/254947/accessing-localhost-xampp-from-another-computer-over-lan-network-how-to
like image 318
ma11hew28 Avatar asked Sep 30 '12 00:09

ma11hew28


People also ask

Why is my Mac not connecting to the server?

Make sure the computer or server is available The computer or server may have been shut down or restarted, or may have been disconnected from the network. Try reconnecting, or contact the person who administers the computer or server.


2 Answers

I had the same problem. I turned off my WI-FI on my Mac and then turned it on again, which solved the problem. Click Settings > Turn WI-FI Off.

I tested it by going to Safari on my iPhone and entering my host name or IP address. For example: http://<name>.local or http://10.0.1.5

like image 184
johnnieb Avatar answered Oct 16 '22 19:10

johnnieb


Have your server listen on 0.0.0.0 instead of localhost.

like image 30
ma11hew28 Avatar answered Oct 16 '22 21:10

ma11hew28