真正的连接装置,Android模拟器 [英] Connecting Real device to Android emulator
问题描述
我开发Android网络应用程序,我仍然坚持我的真正的Android设备连接与我的台式电脑上运行的设备仿真器。
I am developing a network app for Android and I'm still stuck on connecting my real Android device with an device-emulator running on my desktop computer.
我已经建立专用网络的路由器,使连接到网络的,仅仅是我的电脑和我的手机,以避免防火墙/关闭端口的问题。
I've created private network with a router, so the only ones connected to the network are my pc and my mobile phone, in order to avoid firewall/closed ports problems.
我的电脑的IP是192.168.1.100,我尝试ping对方让我可以每个网络节点的海上可达性。平安工作正常,从我的电脑(而不是模拟器控制台)到手机上。
My PC ip is 192.168.1.100 and I'm trying to ping each other so I can sea reachability of each network node. Ping works fine from my PC (not the emulator console) to the phone.
问题是,我想从我的手机ping到PC的模拟器,而不是本身......对于这一点,我用模拟器控制台的PC ......我应该用我的电脑的IP或者我应该用另外一个?我见过一些IP的像10.0.xx在这里的http://开发商。 android.com/guide/developing/tools/emulator.html
The problem is that I want to ping the PC-emulator from my mobile phone, not the PC itself... For that, I use the emulator console... Should I use my computer IP or should I use another one? I've seen some ip's like "10.0.x.x" here http://developer.android.com/guide/developing/tools/emulator.html
不过,我想这些是连接两个模拟器,对吧?
But I guess those are for connecting two EMULATORS, right?
此外,我试着用插座将它们连接,从而为通过模拟器控制台端口重定向,但仍无法连接它们。
Besides, I've tried to connect them by socket, creating a redirection for the port via Emulator console, but still can't connect them.
任何线索?
谢谢!
Any clues? Thanks!!
推荐答案
我试过尽早解决我给你和它没有工作。正如你说也许原因是模拟器控制台的REDIR命令只重定向从本地主机的数据包正在添加
I tried the early solution I gave you and it didn't work. As you said maybe the reason is the redir command of the emulator console only redirects packets comming from the localhost.
所以,我搜索了一个简单的代理服务器,并用它在同一台机器来测试它。
So I searched for a simple proxy server and used it in the same machine to test it out.
http://www.java2s.com/code /的Java /网络协议/ Asimpleproxyserver.htm
有了这个,我采用了以下配置:
With this I used the following configuration:
上的代理:
String host = "localhost";
int remoteport = 3000;
int localport = 4000;
然后运行模拟器实例:
Then run the emulator instance:
- 服务器套接字侦听端口2000。
- 开启远程登录实例,并发出再导向添加TCP:3000:2000
最后在实际设备上打开一个套接字本机地址端口4000。
And finally on the real device open a socket to the machine address on port 4000.
因此,网络地图的样子:
So the network map looks like:
设备< - >机:4000代理机:3000< - >:3000仿真器:2000 - >应用程序
Device <-> machine:4000 Proxy machine:3000 <-> :3000 Emulator :2000 -> Application
这使用设备和仿真器上相同的应用程序为我工作。
This worked for me using the same application on the device and emulator.
这篇关于真正的连接装置,Android模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!