hy again!
I'm trying to connect two emulators running as server and client on the same PC.The thing is that one of them is inside a virtual machine.What addresses should I use for each of the emulators in order to connect between them?
I'm using a TCP based connection!
The first emulator is running on Windows 7
The second one inside the Vmware is on Xp
The IP of my PC inside the network is 192.168.71.1
Really gratefull if u answer.Thx!!
I imagine you'd want to use the localhost address (127.0.0.1). Set the server up to listen and once it is up and running have the client connect and you should be good to go. (Make sure the port you use matches, obviously.)
http://en.wikipedia.org/wiki/Localhost
A few more details would help:
What is the IP address of the VM?
Is it using NAT, bridged networking, or what?
Do you really need to run the 2nd emulator inside a VM - this complicates networking.
UPDATE: Multiple emulators on 1 machine (no VM)
You can launch another emulator from the command-line, using /emulator -avd . You'll need to create a second AVD for this to work. I use Linux, so can't give the exact details for Windows.
UPDATE: Communication between main machine and VM with android emulator
I believe the emulator only listens on 127.0.0.1 for server sockets, so remote machines can't connect in - this is certainly the case for the debug sockets it uses. However, you can set up port forwarding using a similar method discussed in Remote debugging with Android emulator
It's good that you're using bridged networking, as NAT would stop the VM getting inbound connections, so the emulator would have no hope.
UPDATE #2: Port forwarding
You can set up port forwarding between sockets on the local machine and on the emulator, using adb forward. It might also be worth looking at Communication between Android Emulators, there appears to be an undocumented emulator switch -shared-net-id that could help.
Hope this helps
Phil Lello
Related
I want to create a mobile browser app.
I am using ionic within wsl within windows 11.
Now when I do ionic serve --external I want to access the web app from my phone browser.
I am on a public train wifi, so maybe that's why I can't connect?
This is the output from ionic (extract):
[INFO] Development server running!
Local: http://localhost:8100
External: http://172.21.17.144:8100
My phone is on the train network as well. I can access the external ip from my laptop (host), but not from the phone. The phone browser gives timeout message, when I try to connect to the external ip.
I also tried to connect via hotspot. I created a hotspot in windows 11. Connected to it from the android phone. Unfortunately I couldn't connect to my laptop via the hotspot network either (ip: 192.168.37.1). Also I didn't see network adapter that was hosting the hotspot in wsl via ip a.
Please, how would you connect to your dev server, that is running on your laptop, from your phone, without too much headache?
Please, how would you connect to your dev server, that is running on your laptop, from your phone, without too much headache?
There are several options. The first is definitely the easiest, if it works for you.
WSL1
In general, networking is "easier" on WSL1, so if the tools you are using work there, it's okay to keep using a WSL1 instance for them. You can have a separate WSL2 instance if you'd like for tools that work better there.
WSL1 runs as a syscall translation layer in Windows, and as such it shares the same network interface as Windows.
WSL2, on the other hand, is a virtualized environment, using a virtual NIC behind a virtual Hyper-V switch. The WSL2 network is NAT'd behind/inside the Windows network, which is why you can't see it from other devices on the network.
WSL2 does provide a feature known as "local forwarding" that allows the Windows host itself to access WSL2 through the localhost address. However, that doesn't extend to other devices on the network.
So if you do need to use WSL2, there are other solutions:
SSH Reverse Tunnel
My personal preference at the moment, since it simplifies forwarding and firewall rules. See my "Option 2" in this Ask Ubuntu answer for instructions.
There's some one-time setup that might take 10-15 minutes, but after that it's a one-liner to connect the ports before you run start the server.
Bridged network interface
You mention that you are on Windows 11. As long as this is a Pro version or higher (not Home), you could use a new feature in the WSL Preview release to create a bridged Hyper-V switch. I have not tested it myself, but you can find details in this blog post.
Traditional port-forwarding method
The method recommended in the Microsoft Docs is currently to use Windows port forwarding through the netsh interface portproxy command to route the traffic to WSL2. The problem is that the WSL2 address is dynamically assigned each time it restarts), so you have to determine or parse the correct address after each reboot.
I have a normal simple java program running as a server, waiting for a client to connect with TCP.
On another eclipse project, i'm building an android application. That application has to contact the java program running on the host machine to receive a message.
I can't simply use "localhost" to contact the server becouse, supposedly, the emulator runs behind a virtual router and i'll be accessing the "phone"'s network instead of the host machine's network.
So, what ip should I use to contact the host development machine?
The machine is a linux running on a VirtualBox with an Ip of 10.0.0.5.
I've tried to use that ip on the emulator but even so, I can't establish a connection.
I think you want 10.0.2.2. Check out the Android Emulator Networking documentation:
https://developer.android.com/studio/run/emulator-networking.html
I believe you need to enable port forwarding in order to use any kind of network connection in the emulator. You can do this with the adb tool. Check the Android Developer Guides for details.
My company requires VPN to connect to our dev systems and for the first time I'm trying to work on an android app from home. Turns out the emulator doesn't want to use the VPN interface so even though I have connectivity to our dev systems on my VPN-connected laptop the emulator that's running on it does not.
I have thought of 3 solutions to this:
run a VPN client on the emulator, but I was hoping for a simpler solution than that
setting up a proxy server on my local machine
forwarding a port on my local machine
2 and 3 can probably work, but I'd still like to know if there is an easy way to get the emulator to use the VPN interface without a workaround.
I'm running OS X 10.7 and I've already tried adjusting the interface priority order with network>>set service order.
I suppose I can dust off the old dell and try it there, but I would expect the same results.
First start your vpn connection and then restart the emulator, now the emulator should use the host vpn connection.
it's mostly because of the DNS issue, according to the android doc:
At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4, 10.0.2.5 and 10.0.2.6 as needed.
I encountered this issue and tried something on dns settings but I could not solve it. As #machado said in the comment section below you should boot the emulator via "Cold Boot Now" option. I hope this helps.
What I do on my mac is just make sure 'send all traffic over vpn' is checked.
You'll find this setting after you click advanced while having your vpn connection selected in network preferences.
Works well for my situation, but may not depending on the type of VPN you're connecting to.
I had the same issue and solved it by connecting to cisco vpn after the android emulator has started and connected to the internet.
Works for me in windows 7
I setup a vpn connection on Windows. Then I started the emulator. The emulator and everything on my pc started to use that vpn connection.
I'm developing client/server software for Android.
While connected to the phone via USB debugging, I'd like to access the webserver I'm running on my developement PC - using the USB connection.
Is that possible and if so, how ?
I stumbled upon the answer after a night sleep.
Enabling USB tethering on my phone (N1, 2.2.1) gives it and the host computer an IP address. The phone can communicate with my web server running on my developement machine!
(Chris, the rumors are right)
Just make sure your web server is listening on that IP address. For apache, use the line
Listen 80
or
Listen x.x.x.x:80
(x.x.x.x being address of your android tunnel)
The easiest way to do it is via wireless. If you don't have wireless, I'd say bite the bullet and get it, it's going to be a necessity for testing anyway :)
Typically the USB only supports connections from the development machine to the phone (via adb port forwards) and not the other way around. Of course once a connection is created data can move bidirectionally. One could use this to build a tunneling proxy web proxy (one connection in from the development machine to a daemon running on the phone, outbound connections from the phone then tunnel through this)
I have heard rumors though that what you want to do - often called reverse tethering - may be supported in some more recent devices.
Kevin's wifi suggestion may be the simplest with a real device.
On the other hand, unlike typical phones, the android emulator can directly access the development machine's loopback interface at an alias address given in the documentation.
I wanted to know if it is possible the comunication between two Android Emulators started on two different machines networked.
For example
- Emulator A run on machine M1
- Emulator B run on machine M2
Can A and B exchange messages?
If yes, what ip address do I use?
Thank you very much
Deborah
You might know this already. As of android-sdk-tools_r7 it should at least be possible to connect two emulators to each other. Whether is works between physical machines is not something I know. It might be possible to set up masquerading between the two hosts for this specific broadcast.
From the android commit
Enable interconnection of emulators
This patch adds a -shared-net-id option to the emulator which
joins the emulator in a shared network.
If the option is given the emulator is started with an additional
network interface bound to a multicast socket. This multicast socket
emulates a network hub, interconnecting emulators.
If the -shared-net-id option is not given, nothing changes.
To connect two emulators, use the -shared-net-id <number> command line option when starting the emulator. They will then directly share everything sent to or read from ip 10.1.2.<number> on the emulator.
Another approach would be to enable port forwarding between the emulators using adb, and then set up masquerading for those ports on the networked machines.
I'm not really sure that either of these solutions match the use case that you're asking after. If not, adding more details to the original question might help. :)
Disclaimer: I have not tried the first approach, and the second I've only used to make sure that an emulator could bypass a nasty corporate firewall and HTTP proxy so that we could test the android browser. The principle should be sound though.
Update:
Nope, I played around with it a whole lot and found no nice solutions. I am not good enough at iptables to set up a valid tunnel that way that works for the server end.
Regards,
Mikael
An emulator normally has outbound access to the development machine's LAN or internet connection, so the problem is on the inbound side.
You can use an emulator or ADB port forward to send traffic into the emulator, but possibly only locally originating traffic on the development machine's loopback interface, and not external traffic. If that is indeed the case, the simplest thing would probably be to write or configure a port forwarder that listens on the development machine's external interface and forwards to the port that is forwarded into the emulator.