Faust V
Faust V

Reputation: 677

Cannot access localhost web service from Android device

I have built a web service with CakePHP for my own testing purpose.

Now I use my real Android device to connect my web service (@localhost). At first try, I managed to load my test page. Then, I turned off the Apache server and test it to make sure it is not available. After the test was done, I restarted Apache again. However, since then my Android device cannot load my page (Web page not available). I have Digest Authentication on my web service folder and at first try, it was properly executed...

What I've done so far is:
1. Connected my localhost (http://192.168.xxx.xxx) using my real Android device (not an emulator).
2. Digest Authentication pops up.
3. Enter username & password. Successfully connected.
4. Turned off the Apache Server.
5. Try to connect my localhost again (of course, "web page not available").
6. Restart the Apache Server.
7. Try to connect my localhost again (reload never works again...)

At first I thought it may be cache problem or something. So I have cleared all cache & any form data of my Android's web browser and tried reload again. But it never reload again. Then, I tried to connect from another PC and it successfully connected. Only from Android device fails to reload my page.

Is there anything I can do to solve this problem? I need to use my real Android device for debugging purpose because the emulator is too slow for the job. I have searched around and found several similar questions, but none of them didn't help because in my case, I once have successfully connected to the service. Just once failed to reload the page and never load it again...

Thanks in advance.

* EDIT * I just tried the same sequence using Android emulator and it successfully reloaded... I have even tried another browser (Dolphin Browser) for my real device and still cannot load my page...

Upvotes: 1

Views: 5556

Answers (1)

einnocent
einnocent

Reputation: 3954

Possibly the web server is listening on the loopback interface but not on the network interface. This means that hits on 127.0.0.1 and localhost will work, but 192.168.xxx.xxx will not (whether from localhost, LAN, or WAN).

To determine which interface the server is listening on, look here for a command to tell you about the listening ports (I used lsof -Pan -i tcp -i udp). Then look for your server process in the list. For the lsof command, if for port 8888 you see something like TCP *:8888 (LISTEN) then your server is listening on all interfaces. But if you instead see something like TCP [::127.0.0.1]:8888 (LISTEN) then you have identified your problem!

The next step to solve your problem is to set up your server's run configuration to listen on all interfaces. I don't know anything about CakePHP, but if you can specify an IP address, then you may want to try 0.0.0.0. Usually you can do this near where it lets you specify the listening port. Thus, if you have a configuration like:

--port 8888

Then you can try:

--port 8888 --address 0.0.0.0

Upvotes: 1

Related Questions