File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes Socket communication outside emulated app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Socket communication outside emulated app" Watch "Socket communication outside emulated app" New topic

Socket communication outside emulated app

Marek Borshop

Joined: Nov 26, 2010
Posts: 5

I'm trying to deal with a problem, which is a known issue, but I couldn't find any reply to this so far. I have an Android application (which I run on an emulator within Eclipse) and I need to perform a socket communication with a Java server appliaction running on the same computer. It won't connect. The server is running properly (has been tested), but the client (android app) can't connect to the server in any case. Can you recommend what to try? I know I cannot use "localhost" or as it refers to the emulator's loopback, not the computer's one. Yet, no other IP address I pass to the Socket constructor works.

This is my Android client app's attempt to connect:

Socket connection = new Socket(InetAddress.getByName("anything"), 12345);

- if I put "localhost" or instead of "anything" I obviously end up with "connection refused" exception.
- if I put any number as IP address (either directly here or via InetAddress.getByAddress()) the app halts and the log says "launch timeout has expired. giving up wake lock" and does not proceed any further. I tried random addresses, my ethernet NIC's address (which is pingable) and nothing works.

I can't get through this. Any advice would be appreciated!

Much thanks!

Marko Gargenta

Joined: Mar 27, 2011
Posts: 18

So, emulator has its own IP:

setprop net.eth0.dns1
setprop net.gprs.local-ip

But keep in mind that emulator is basically a virtual machine inside of your host computer. So, as such, it's sharing your hosts tcp stack.

I hope this helps.
I agree. Here's the link:
subject: Socket communication outside emulated app
It's not a secret anymore!