1

I have several applications on my device that can run HTTP servers. I can access the server just fine if I user the actual private IP address, but localhost, 127.0.0.1, and [::1] all fail to access the server. Before you ask, the port and protocol are both correct since I use them in accessing my device's server through its private IP address. Why won't this work? How do I get it to work?

  • 1
    You need to run your server on all the interface or explicitly at localhost to do that. If you bind the server to a particular network such as ethernet or Wi-Fi, accessing localhost would do no good. Many Android apps that are in the business of hosting a server provides a setting to choose an interface. Try changing it to localhost or All. – Firelord Dec 21 '18 at 15:15
  • @Firelord I have no idea what an "interface" is here. – Melab Dec 21 '18 at 15:52
  • You would have a setting like this in your server app. i.stack.imgur.com/VPzA6.jpg – Firelord Dec 21 '18 at 16:46
  • @Firelord It isn't my application. I did not write it. Servers, in any case, don't have control over whether or not they can be accessed from localhost. – Melab Dec 21 '18 at 16:54
  • 1
    You misunderstand. A server app has every control on which interface the server should be listening to. If you cannot access your server through localhost then it means your server is not configured to listen on localhost network interface. It would be better if you at least link one app you are using to host an HTTP server. – Firelord Dec 21 '18 at 17:03
1

Localhost won't work because the server app that you're using is not configured to listen localhost network interface. I even doubt that the http server (web server) you're using has capabilities to listening on the loopback interface. Thus you need to be using private IP address instead (on the network interface i.e wifi, ethernet, etc) .

In fact as discussed by Firelord and Irfan, you'd need to be using a real, dedicated webserver application that has the ability to listen on all network interfaces. Then bind the server to the localhost (or loopback interface)

Additionally if you are using localhost, resolvers may or may not resolve that to 127.0.0.1 if it's not explicitly mentioned in /etc/hosts

  • Did this help? Please don't forget to upvote/accept if it helped ;) – xavier_fakerat Dec 30 '18 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.