从 Android 模拟器访问本地 VirtualBox 上的 Node.js
作为学习 Node.js 的一部分,我决定将其用作 Android 客户端的服务器端。 我部署了一个带有 Node、NPM、Android SDK 和 Netbeans 7 的 Ubuntu 11 VirtualBox,然后就开始使用它了。
问题:我无法从模拟器访问本地主机。
这是我尝试过的:
1. 节点“hello world”脚本:
var app = require('express').createServer();
app.get('/', function(req, res){
res.send('Hello World\r\n');
});
app.listen(3000);
2. 终端 > ifconfig
返回“inet addr:10.0.2.15”
3. 终端> curl 10.0.2.15:3000
-> “你好世界”
4.浏览器> http://10.0.2.15:3000 -> “你好世界”
5.安卓模拟器>应用程序尝试访问 http://10.0.2.15:3000 -> “与 http://10.0.2.15:3000 的连接被拒绝”
6.安卓模拟器>安卓浏览器>> http://10.0.2.15:3000 > “网页不可用”
只是为了验证,我做了 Android 模拟器 >浏览器>任何其他页面 - 都可以。
所以看起来Android模拟器无法访问本地VirtualBox IP。
我的 VBox 内没有运行防火墙,并且我知道模拟器内没有可以更改的设置。起初我以为这是我的应用程序(尽管它是一个虚拟的“获取 url”小应用程序,其清单中包含 android.permission.INTERNET
),但我什至无法从浏览器访问它。
我错过了什么方向或想法吗?
感谢您的时间和帮助!
盖伊
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
明白了(我想!)
感谢 cababbunga 的评论,我开始搜索“模拟器 IP”并找到 这个问题,答案是始终可以在 10.0.2.2 处访问本地计算机。
我尝试了一下,它在浏览器和应用程序中都有效!
感谢您让我走上正轨!
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!