Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket communication outside emulated app

 
Marek Borshop
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic