This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Socket communication outside emulated app

Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!

Posts: 18
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic