9

Emulator can access web service fromlocal host but my real device cannot although I use LAN ip address (192.168.xx.yyy) instead of 10.0.2.2. Of course, my android mobile was recognized by adb and it connected my laptop via usb port.

I already read some similar questions at stackoverflow but still didn't know how to access webservice from a real android mobile. The answer of this question How can I access my localhost from my Android device? my be useful but i don't really understand that answer.

Anyone helps me? Thanks you!

Community
  • 1
  • 1
Wayne
  • 6,361
  • 10
  • 46
  • 69
  • try this: http://stackoverflow.com/a/17603378/1600061 – Zsivics Sanel Jul 11 '13 at 20:59
  • Though i know it's late but for new people who have a problem like this please see --> 192.168.1.yyy i got this same problem since 192.168.0.yyy is for browser and 192.168.1.yyy for mobile devices in my case that resolved everything for me. Contact your system administrator or ask some senior programmer. Enjoy Programming! – SameerKhan1406 Nov 16 '16 at 06:35

3 Answers3

10

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 what server you are using, 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

einnocent
  • 3,567
  • 4
  • 32
  • 42
0

In my opinion, the below point is more important for developer community

I am not a network expert; like me many developers may be there.

change to 0.0.0.0:80 in httpd.conf is very important.

In normal(default) settings, port 8888 throws error in WAMPSERVER (even in Windows Browser). That is why I explained the exact environment where port 8888 throws error.

Specific information about what configuration throws error and what configuration works successfully is more important.

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
Kuppuram
  • 997
  • 6
  • 3
-2

Have you tried using a wifi router which is connected to your LAN? Then you just need to connect to the wifi using your mobile and you should be able to access (192.168.xx.yyy)

rfsk2010
  • 8,571
  • 4
  • 32
  • 46
  • I already tried. I unpluged usb cable and connected mobile to to same LAN as laptop(Now my mobile and laptop have the same IP) but i still counld not access webservice from mobile. – Wayne Nov 30 '11 at 09:24
  • Can you access the web service from a different machine? do you need to mention a port number? Is a firewall blocking access to the webservice? – rfsk2010 Nov 30 '11 at 09:28
  • Different machines in the same LAN cannot too. I don't know why huh – Wayne Nov 30 '11 at 09:51
  • Ok. Make sure the webservice is running? ensure the port number, check the iss config. also check if firewall is blocking the ports. Once you get it working and you can access the webservice from different machines, you will be able to access it from your android device. – rfsk2010 Nov 30 '11 at 10:10
  • Of course the webservice is running (i can access it from emulator). The webservice, i just Ctrl-F5 from Visual Studio 2010 and it started webservice, no iss. Firewall already turned off. But i still could not access webservice from a real device :( – Wayne Nov 30 '11 at 10:15
  • You mean **192.168.xx.yyy**. It is confusing for someone that does not know – kon psych Apr 02 '13 at 12:11