1

As part of learning Node.js, I decided to use it a s a server side for an Android client. I deployed a Ubuntu 11 VirtualBox with Node, NPM, Android SDK and Netbeans 7 - and went to it.

The problem: I cannot access my local host from the emulator.

Here's what I tried:
1. The Node "hello world" script:

var app = require('express').createServer();

app.get('/', function(req, res){
    res.send('Hello World\r\n');
});

app.listen(3000);

2. Terminal > ifconfig returned 'inet addr:10.0.2.15'
3. Terminal > curl 10.0.2.15:3000 -> "Hello World"
4. Browser > http://10.0.2.15:3000 -> "Hello World"
5. Android emulator > app trying to access http://10.0.2.15:3000 -> "Connection to http://10.0.2.15:3000 refused"
6. Android emulator > Android browser > http://10.0.2.15:3000 > "web page not available"

Just to verify, I did Android emulator > Browser > any other page - works.
So it looks like the Android Emulator cannot access the local VirtualBox IP.

I have no firewalls running inside the VBox, and I know of no setting inside the emulator I can change. At first I thoyght it was my app (although it's a dummy "get url" small app with android.permission.INTERNET in its manifest), but I can't even reach it from the browser.

Any direction or idea I missed?
Your time and assistance is appreciated!

Guy

Nemanja Trifunovic
  • 24,346
  • 3
  • 50
  • 88
Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
  • 1
    What IP address is assigned to your Android emulator? IIRC by default it's same 10.0.2.15. – cababunga May 30 '11 at 21:34
  • You are trying to combine two networking "hacks" which do not play well together, especially as they both seem to give special meaning to the 10.0.0.0 subnet. Try moving the virtualbox subnet to a different one. Also consider forwarding a local port into virtualbox to the port where your server is listening, for example by ssh'ing into it from the physical machine and reading up on ssh port forwards, then contact that port from the android virtual device at the special alias for the hosting pc's loopback address. – Chris Stratton May 30 '11 at 21:37
  • @cababunga - how can I find out the IP of the emulator? And how will I be able to change it, if you're right? – Traveling Tech Guy May 30 '11 at 22:14
  • @Chris - thanks for the long comment, but I'm not sure I'm quite following. What "hacks" am I using/combining? And what would be the easiest, shortest action to take on this? – Traveling Tech Guy May 30 '11 at 22:15
  • Both the emulator networking and virtualbox networking go to lengths to partially simulate networking, but imperfectly. Cleanest would be to dropvirtualbox and run the server natively on that pc or another. If that is not an option, read up on ssh port forwards. – Chris Stratton May 30 '11 at 22:46
  • Thanks @Chris, found the right IP. Seems like the emulator is indeed using the same subnet. – Traveling Tech Guy May 30 '11 at 22:56

1 Answers1

4

Got it (I think!) Thanks to cababbunga's comment, I started searching for "Emulator IP" and found this question with the answer that the local machine can always be reached at 10.0.2.2. I tried it and it works in both the browser and the app!

Thanks for putting me on the right track!

Community
  • 1
  • 1
Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159