Is there an easy way to setup the android emulator to access the LAN of the host machine?

后端 未结 4 790
生来不讨喜
生来不讨喜 2020-12-09 18:07

I would like to access a web service provided by one of the machines on my LAN from the android emulator.

If the service was running on the same machine where the em

相关标签:
4条回答
  • 2020-12-09 18:54

    Well, it just works (TM).

    In the android emulator manual that I had read before testing (I try to RTFM before doing things) this is stated:

    Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.

    This made me think that it could not access my LAN. I was wrong, just adding the IP of the server on my LAN allowed me to access it from the emulator.

    0 讨论(0)
  • 2020-12-09 18:57

    As we know, emulator can access host machine by IP 10.0.2.2, so I tried IP forwarding but I could not make it working.. :|

    I followed link below for forwarding request from localhost(10.0.2.2 in case of emulator) to the other machine in LAN.

    http://www.debuntu.org/how-to-redirecting-network-traffic-a-new-ip-using-iptables

    0 讨论(0)
  • 2020-12-09 18:58

    as of 2018-08 it seems the "it just works (TM)" certificate has been revoked

    here is what I needed to access a server in my local network:

    host ip (my pc): 192.168.15.102/24 
          server ip: 192.168.200.33/24
    

    create a port forwarding rule in an elevated command prompt on host using netsh

    netsh interface portproxy add v4tov4 listenport=80 connectport=80 connectaddress=192.168.200.33
    

    start the mobile device emulator and browse to 10.0.2.2 (as mentioned in the documentation):

    10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

    0 讨论(0)
  • 2020-12-09 19:04

    You could get an actual android device and connect it to the LAN (i have done this).

    How are you connecting to the host machine? through html? because if your app requires a hard line connection to the machine then its not a very good solution for a mobile device.

    0 讨论(0)
提交回复
热议问题