1

Searched all over the place for a fix for this or even a good way to troubleshoot it. I've read the previous SO threads that seem to cover this issue but nothing in any of them has worked in my case. Basically, I can't get access to anything that is being served via localhost on my mac in any browser on my Android device.

This is happening despite the fact they are connected to the same WIFI network and I am using the correct network address for my mac on which localhost is running (I have checked and double checked several times). I have no idea what the problem is because it worked perfectly fine before and I haven't changed anything that I believe would interfere with localhost access.

I don't have firewall or port blocking settings on my router either.

I have also tried on several different Android devices to eliminate it being a problem specific to one particular device.

Totally stumped. Any clues or hints on how to fix this would be much appreciated!

***** UPDATE *****

I tried using python -m SimpleHTTPServer 3000and it works. The site is accessible on my Android device. So I am pretty sure it is not a network issue per se.

The site is essentially a Node app which I built using the angular-quickstart template found here. It launches lite-server when npm start is run. Hope that gives some further insight into what the problem might be.

mikeym
  • 5,705
  • 8
  • 42
  • 62
  • Your question is worded a bit oddly. Localhost is the current device. Running a server on localhost from your phone's perspective means it would be running on the Android phone itself. If you have a server on your mac it would just be a server, it would absolutely NOT be open only to localhost or it would be unreachable by any other computer. – Gabe Sechan Dec 30 '16 at 23:52
  • Just to be clear, the localhost I am referring to is a server running ONLY on my mac. I am trying to access the files being served FROM this server over my WiFi network on my Android device(as one would for any other files served by http). I am in no way trying to access localhost directly on any other device other than the machine on which it is running. – mikeym Dec 31 '16 at 04:34
  • @GabeSechan if you can tell me how I might reword this question to make it clearer I'd be grateful. I couldn't think of any other way of phrasing it. Thanks for the input! – mikeym Dec 31 '16 at 04:45

1 Answers1

0

If you open up a terminal on your mac and then run the command ifconfig it will tell you what ip address all your interfaces have. It is probably your en0 interface. That ip address should be used in your browser on your Android device.

You will have to make user that you server (web) is binding to the correct ip address as well. You could be binding to all ip addresses if possible.

Ray Hunter
  • 15,137
  • 5
  • 53
  • 51
  • a "netstat -nlp | grep 80" from the mac would solve a lot of doubts here. – Tharaka Devinda Dec 31 '16 at 17:42
  • 1
    @TharakaDevinda -p is not supported on mac FYI. – Ray Hunter Dec 31 '16 at 17:46
  • oops sorry about that. – Tharaka Devinda Dec 31 '16 at 17:49
  • @srayhunter Unfortunately `ifconfig` just gives me the same ip address that I already obtained from the Network section of System Preferences on my mac. So I am sure I am using the correct ip and port that my site is running on(192.168.0.101:3000). I am not sure how to "make sure my server is binding to the correct ip address". This isn't something I've had to do in the past. It just worked. How can I check? Thanks for the response! – mikeym Dec 31 '16 at 19:07
  • @mikeym if you are using rails check this out - http://stackoverflow.com/questions/28668436/how-to-change-the-default-binding-ip-of-rails-4-2-development-server – Ray Hunter Dec 31 '16 at 19:55
  • @srayhunter Not using Rails unfortunately. But I think I have narrowed it down to a problem with Node. I can get it to work on my phone when I use `python -m SimpleHTTPServer 3000` so it appears not to be a network issue directly. When I `npm start` I can't get access. – mikeym Dec 31 '16 at 23:39
  • @mikeym how you are starting your node server? There should be a bind option when you start it. – Ray Hunter Jan 01 '17 at 03:08
  • @srayhunter I'm starting the server simply with `npm start` at the moment. I checked the readme and can't see any binding options. There is another option `npm run lite` which I tried but that doesn't fix it. – mikeym Jan 01 '17 at 22:14
  • @mikeym check this out - http://stackoverflow.com/questions/14043926/node-js-connect-only-works-on-localhost – Ray Hunter Jan 03 '17 at 17:07
  • @srayhunter Yeah I saw that SO thread already but sadly it won't work in this case because the `angular-quickstart` doesn't have the same type of config file access. However, I did manage to change the port to `8080` by adding a `bs-config.json` suggested at http://stackoverflow.com/questions/35516783/how-can-you-specify-ui-port-for-lite-server. But still getting `This site can't be reached` on phone. Very frustrating! – mikeym Jan 03 '17 at 18:45