6

I want to connect to my local Web Server (NodeJS server) which runs on my MacBook with my iPhone.

On my Mac I can access the server via http://localhost:3000/. Now all it should take is to replace localhost with my Mac's local IP address like this http://192.168.0.13:3000/. However, on my iPhone I cannot access the server this way and even when I try to open http://192.168.0.13:3000/ on my Mac there is no connection being established.

This is definitely a problem with my Mac and not with my program because when I run the server on Windows and try to connect to it with the local IP address it works just fine.

Also trying this in another Wi-Fi Network does not help or changing the port does not change anything either.

I am using Mac OSX 10.11.5 and my firewall is turned off.

How can I solve this problem?

Routing Tables (netstat -r)

(Deleted)

  • Comments are not for extended discussion; this conversation has been moved to chat. – bmike Aug 21 '16 at 18:12
  • I was tempted to vote to close as too broad, but from all the comments - let's see if an overview of how to determine if the OP thinking it's really on the Mac is in fact the cause. – bmike Aug 21 '16 at 18:18
  • Hi HansMu158, did you ever figure out why browsing to your server's IP address didn't work? I may have a similar problem as yours and wonder if you have suggestions. Thanks! See: apple.stackexchange.com/q/284762/53510 – Ryan May 25 '17 at 15:38
  • 1
    @Ryan Yeah, I figured out that the problem was caused by an old anti virus program (Eset) I had on my Mac which, although it was neither active nor running, had a firewall which blocked almost all incoming traffic. I had a brief look at your problem… When you are developing with a local server it is necessary to set the hostname of the server to "0.0.0.0" to allow access from your network. Maybe your developing environment is not doing that by itself, so you could have a look into that. – HansMu158 May 27 '17 at 10:21
  • I found that none of the answers below worked using the Safari browser, but when I changed to Chrome, I could view the server at myname.local:3000, where myname is the name of the machine running the server. – Obromios Sep 17 at 0:50
1

As far as I can tell the behavior is correct. A basic node web server uses dns.js to resolve any hostname – which itself uses the system's DNS resolution method.

A hostname "127.0.0.1" as well as "localhost" can't be resolved by OS X's mDNS responder (neither non-reverse nor reverse).

So either use your Mac's IP (i.e. 192.168.0.13) or its hostname (e.g. tims-macbook-pro) as hostname. To advertise the service in Bonjour you have to use dns-sd.

Or create several listening IPs like in this q&a.

  • That may be correct, but it also does not work with a MAMP Apache Server. Also the same configuration works on Windows which is something I do not quite understand. – HansMu158 Aug 21 '16 at 18:38
  • @HansMu158 Please ask a second question regarding your MAMP config & node. If possible include some relevant parts of the config files (e.g. apache), a somehow stripped *.js file containing the http.createServer(handler).listen part and the MAMP config details. – klanomath Aug 21 '16 at 18:43
  • I really think this problem is not specific to MAMP and my Node JS server. Firstly, the Node Server can be run and accessed via local IP on windows. Furthermore even ssh-ing into my MacBook (which is enabled under sharing) does only work with local host, not with local IP. So ssh Tim@localhost works just fine, whereas ssh Tim@192.168.0.13 gives me the following error: ssh_exchange_identification: Connection closed by remote host – HansMu158 Aug 23 '16 at 6:27
  • Is there any way for me to see which connection are incoming on the Mac and which are let through or blocked? – HansMu158 Aug 23 '16 at 6:39
  • And as response for the ssh problem: I do not use non-OSX ssh solutions and /etc/hosts.deny and /etc/hosts.allow do not exist. After deleting the whole ~/.ssh/known_hosts file, ssh still not works and gives me the same error. The file ~/.ssh/authorized_keys does not exit either. – HansMu158 Aug 23 '16 at 6:45
0

You can resolve this issue in three ways:

  1. Run a port scanning tool from the iPhone to make sure the port is actually open on the Mac. Firewall rules, improper NAT, router / switch issues all can be the cause of another device not getting the correct route to your Mac. If the PC can port scan or browse the Mac web server, you'll know it's not necessarily the Mac.
  2. DNS issues - instead of hard coding the IP address, you could navigate to http://192.168.0.13.xip.io - that will make sure the web browser works if the iOS device is on an IPv6 only configuration. Unlikely, but at some point this will be more common. You could also use the Mac's IPv6 address instead of the IPv4 address.
  3. Proxy setup on iOS - again, if your iOS device has a VPN or web proxy configured, it won't necessarily get to the Mac web server. The steps to triage that are also varied.
  • 1. The iPhone Port Scanning Tool shows the port is open. Also a Port Scan on Mac finds the port. – HansMu158 Aug 21 '16 at 18:29
  • 2. Switching to this URL sadly does not work and 3. I do not have a proxy set up on my iOS device – HansMu158 Aug 21 '16 at 18:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .