wood burning stoves 2.0*
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
Author

Socket communication outside emulated app

Marek Borshop
Greenhorn

Joined: Nov 26, 2010
Posts: 5
Hi.

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 127.0.0.1 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 127.0.0.1 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!

Marek
Marko Gargenta
author
Greenhorn

Joined: Mar 27, 2011
Posts: 18

So, emulator has its own IP:

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

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: http://aspose.com/file-tools
 
subject: Socket communication outside emulated app
 
Similar Threads
how to connect to other machine rather than localhost.
problem with sockets :S
RMI Server Configuration
Problem connecting to "localhost"
Is there any danger to exposing an RMI port/server to the internet?