赞
踩
Your computer and Android device may talk to each other perfectly, but it does not work when you want to send data to you Emulator. In fact, each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. So you may get IP address like 10.0.2.15 on your Emulator.
In order to receive data on your Android Emulator regularly, open your command line console and type two commands.
Step 1: Connecting to the console of the target Emulator instance, specifying its console port number, as follows:
telnet localhost <console port number>
Console port number can be found on the title of the Emulator, and the console port number for the first emulator instance launched is 5554.
Step 2: Using the redir command to work with redirections.
redir add <protocol>:<host-port>:<guest-port>
Here, <protocol> is either tcp or udp, and <host-port> and <guest-port> sets the mapping between your own machine and the emulated system, respectively.
For example, the console port number of the Emulator instance is 5554, and the listen port for receiving UDP data in my application is 2011. Type the following two commands:
telnet localhost 5554
redir add udp:2011:2011
Now I can receive the data from IP address of my host (development) machine and the port 2011.
For details, please visit http://developer.android.com/guide/developing/devices/emulator.html
Note:
If your host machine is based on Window 7 system, you have to open the telnet client first. It can be done through Control Panel -> Programs and Features -> Turn Windows features on or off -> Telnet Client.
The Android Debug Bridge (ADB) tool provides port forwarding, an alternate way for you to set up network redirections. Visit http://developer.android.com/guide/developing/tools/adb.html#forwardports for details.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。