The ADB tool in Android SDK is convenient utility for debugging and control Android emulators. One of its powerful features is it can forward a TCP port on local machine to an emulator running on the same machine.
After you run the ADB forward TCP: hostport TCP: emuport command, Your android running in emulator can listen on emuport and communicate with external applications running on host machine. from the external application's point of view, it's connecting to hostport rather than emuport. the ADB is responsible for forwarding messages between the two.
But ADB has a limitation of only accepting connections from the same machine, you can't connect from a machine that ADB isn't running on. this limitation makes it a little bit inconvenient to do network programming. especially on Windows, if you want to use Wireshark to capture the packages between emulator and external app. by default, Wireshark isn' t able to capture loopback packages on Windows. so, we change the behavior of ADB to accept remote connections.
(Another way to overcome this is instead of capturing network package on host side, we can use tcpdump on emulator side. For example, use"
/Data/tcpdump-s 1500-VV-W/data/net. pcap UDP port 5060"To capture all packages for UDP port 5060 and save them in/data/net. pcap file. the-S parameter specifies the size of each packet whose default value is 68, too small to get some useful information truncated. the/data/net. pcap file can also be examined with Wireshark .)
How to modifyDBBehavior
If we run netstat command on host side, we can find out that ADB server process binds to the loopback address. So it can't be accessed via external address.
The ADB register a port forwarding information throughInstall_listenerFunction. AndInstall_listenerCILSLocal_name_to_fdFunction to bind to a local address. InsideLocal_name_to_fd, It starts a TCP server throughSocket_loopback_server. To change this, we can useSocket_ipaddr_any_serverWhich binds to all ipaddresses. In this way, the ADB server can forward a request from remote machine to emulator.
How to compile
In order to get the modified ADB, We need to compile it. to do so, we first need to download all of anroid's source code. then, at the root of andoird source directory, run./Build/envsetup. Sh. Finally, runMake ADB.
Downloads
Http://rxwen-blog-stuff.googlecode.com/files/tcpdump.zip
Http: // rxwen-blog-stuff.Googlecode.com/files/adb-Linux.zip
Http: // rxwen-blog-stuff.Googlecode.com/files/adb-Windows.zip