Receiving network data on Emulator

 

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值