我正在尝试编写我自己的android http服务器。这是相当好,但我有一个问题,我的AVD。我不想在每次测试更改时都下载我的应用程序到手机上。我想通过AVD连接到我的应用程序。要使用此函数获取ip地址,请执行以下操作:
private String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); }
}
}
} catch (SocketException ex) {
Log.e("ServerActivity", ex.toString());
}
return null;
}在我的手机上一切正常,但当我在AVD上运行我的应用程序时,它显示ip: 10.0.2.15,我无法连接到它。有没有办法连接到我在AVD上运行的应用程序?如果这很重要,我的应用程序使用端口8080。
发布于 2012-06-14 10:14:30
Telnet到设备(假设它位于端口5554):
telnet本地主机5554
在Android控制台提示符下使用重定向:
重定向添加tcp:8080:8080
将你的浏览器指向'http://127.0.0.1:8080/‘,现在应该会发送和接收到AVD。
由:http://www.rhill.co.uk/?p=35提供
发布于 2011-09-16 23:54:12
虽然我不知道你的问题的直接答案,但我知道当从AVD连接到你的计算机时,你必须使用10.0.2.2,因为你的AVD本质上是在另一个“路由器”后面。它不能从您的路由器获取本地lan IP。有关详细信息,请参阅this问题。在this链接中,他引用了:
仿真器的每个实例都在虚拟路由器/防火墙服务后面运行,该服务将仿真器与开发计算机的网络接口和设置以及internet隔离开来。模拟设备无法在网络上看到您的开发计算机或其他模拟器实例。相反,它只能看到它通过以太网连接到路由器/防火墙。
https://stackoverflow.com/questions/7447221
复制相似问题