Connecting an Android device to a web service on a local host

I have implemented a web service for an Android app. The web service runs on my local host (192.168.1.2). Using the Android emulator, I was able to connect to the web service. I tried to connect my Android device in debug mode to a web service, but this did not work. So my question is, is it possible to connect an Android device to this web service that runs on my local host (192.168.1.2), without using a real IP address?

+45
android android-emulator
May 30 '11 at 13:01
source share
11 answers

Have you solved your problem? I also have a problem like you. These are the steps that I have already taken:

  • disconnect the lan cable or turn off any other internet connection from your computer.
  • connect your Android player to your computer using usb.
  • enable usb tethering
  • return to your computer. check your ip. mine is 192.168.42.37
  • check your webservice application on your computer. let's say http://192.168.42.37/webserviceapp
  • Back to the Android mobile phone. try this url http://192.168.42.37/webserviceapp

Now you can access your web service on your PC from your mobile phone.

+31
Dec 29 '11 at 9:40
source share

This is a much simpler way supported by google!

  • Connect the phone via USB to the computer and enable usb debugging
  • On your computer, open the Chrome browser and enter this exact address: chrome://inspect/#devices enter image description here
  • Now you can link your computer port to your device port using the port forwarding button. On my computer, I have a service at localhost:61437 , and I just associated it with the device port 8081. Remember to check the box next to “Enable port forwarding”.

enter image description here

  • screen from service on my computer ( localhost:61437 ) enter image description here

  • from my mobile browser with the same service ( localhost:8081 ). And so it is. You also use this service address in your application. enter image description here

+20
Apr 15 '16 at 11:06
source share

Well, your localhost is 127.0.0.1 (or :: 1), and your LAN IP is 192.168.1.2. Each computer / device connected under your local network can reach your web service over IP 192.168.1.2.

Your Android device must be connected to the same LAN via a Wifi connection so that it can talk to 192.168.1.2.

If you can’t connect your Android device under the same local network, for example, you only have a 3G connection that you need to play with your router / firewall to redirect all incoming traffic (maybe only http traffic) from your public ip address private ip (192.168.1.2)

Hope for this help

+13
May 30 '11 at 13:37
source share

I will abandon my process since nothing on SO helped me. Here are the steps I took to connect my physical Android device to a web service running on my laptop (connected to the phone) on localhost:

  • Enable USB debugging on Android device

  • Launch the web service on your computer. My web service runs on localhost, port 3000 in development: http://localhost:3000/api/...

  • Run ifconfig (Unix) or ipconfig (Windows)

  • Find your inet address on your LAN . Mine 10.0.0.121 for the wlan0 interface. Outwardly, it is 68.43.XX.XXX, which is not the address you want to use.
  • Use the LAN IP address because you are connecting to your service on the local network, otherwise you may receive an econnrefused error econnrefused (connection refused) due to firewall rules.
  • Create your http url with that IP address and the port your web service is running on. For me, this is http://10.0.0.121:3000/api/...

When you launch the application, you should connect to your local web service in logs, Wireshark, etc., and you should see the desired activity / data in your Android application.

+4
Apr 01 '15 at 23:10
source share

I had the same problems, many investigated and then found out that you must explicitly make changes to your firewall settings. Your firewall blocks access to your code from an external source. So, all you have to do is go to the firewall settings, add port 80 (in my case since I use Apache http Server) for inbound and outbound. Now you can test it in your phone browser http: //192.16 .. **: 80 /

+2
Apr 28 '15 at 11:30
source share

I agree with the other answers as a good approach if you do not want to disclose your DEV web service on the Internet. However, it’s much easier if you just expose the web service. There are a number of free DNS services out there, but I found no-ip is the easiest to configure. I use it precisely for the purpose you requested; so I can test my web service DEV on a real device.

If you decide to go without no-ip (I have no connection with this company, this is only the one I used and is familiar), you can get a free public URL, for example http: //MyExampleWebServer.no-ip-org , and no -ip has a utility that you can install, even if you are behind a dynamic IP address, it will always support the correct external IP address associated with this URL. If you are working from your home, you just need to make sure you transfer traffic from port 80 to your internal address 192.xxx (or any other port that you use e maybe 443 for ssl).

It's that simple, and now you can hit this web service from any device that can access the Internet.

I did not work with him, but I believe that dyndns also offers a similar service.

+1
Mar 21 '13 at 19:48
source share

I did this on a Mac using GasMask and Charles Proxy Server. Your phone and computer must be on the same network.

let's say that the web service url you want to get is at http://api.xyz.com , you first use GasMask to point this url to your local host, then use Charles configured a proxy server . Then you go to the settings on your phone, go into Wi-Fi, long press on the network you are connected to, select "Change network" and enter the proxy settings that Charles gave you.

+1
Mar 21 '13 at 19:59
source share

This is a solution for the GAE development server in Eclipse

Step 1: Obtain the LAN IP Address

Go to the Windows Command console (press Win + R, then type "cmd"). In the console, enter "ipconfig". You will see a list of displays. Under the Wi-Fi wireless LAN adapter, get the IPv4 address. It will be something 192.168.xx

LAN IP: 192.168.xx

Step 2:

Go to Eclipse, open the configured server

Gae server

In the "GAE Development Server Properties" section → Address of the local interface for binding, enter the LAN IP address and save.

Step 3:

You can now access the GAE server using

http: //192.168.xx: 8888 /

8888 - indicates the port number, as indicated in the GAE development server

0
Apr 01 '16 at 9:58 on
source share

To access local web services using your own server nodes, rather than IP addresses with ports, follow these steps:

  • Make sure your Android device and local computer are on the same network.
  • Install SquidMan on your Mac, Linux, or any other proxy server.
  • Configure the HTTPPort proxy server (for example, 5555) and clients (for example, 192.168.0.0/24) on your own netmask and start the proxy server.
  • You use web services in:

    but. Web browser Configure the proxy settings for your Android device on Modify WiFi networks.

    b. Android app: Configure proxies for your HTTP client. If you are using Volley, check this out: Volley Behind proxy server .

  • Now you can connect to it using any URL that you use on your host to connect to the web service (for example, http://my-local-machine.com )

Hint: if you get 4xx response codes, make sure your web service allows connections to other non-local hosts.

0
Mar 19 '17 at 8:29
source share

In my case, none of these solutions work because the Windows Firewall blocks it, but the inclusion of the rule in the firewall does not affect.

The problem in my case is that my laptop is connected to Wi-Fi, and Windows has a Wi-Fi connection, for example, on a public network. I have to change the network connection to the private network. http://www.comofuncionatodo.net/tecnologia/informatica/como-cambiar-de-red-publica-a-red-privada-en-windows-10/

0
Aug 23 '17 at 10:55 on
source share

If you are linking to your local host on your system from an Android emulator, you should use http://10.0.2.2:8080/ since the Android emulator works inside a virtual machine (QEMU), so here 127.0.0.1 or localhost will be its own feedback address emulator.

-3
Nov 10 '15 at
source share



All Articles