Reputation: 283
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.
Upvotes: 13
Views: 7250
Reputation: 1700
I think you want 10.0.2.2. Check out the Android Emulator Networking documentation: https://developer.android.com/studio/run/emulator-networking.html
Upvotes: 16
Reputation: 83517
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.
Upvotes: 1