Android Socket Communication thru ADB

I hope, most of the Android Developer know about ADB (Android Debugging Bridge) Tool. It is very handy to make a quick connection to an Android target (Emulator or Device) for debugging and has number of useful options (shell, install, push, pull, forward, etc ..). The ADB Forward option is a less used option. It is very useful for making a socket communication between the target and host with-out getting into complex socket programming.

Format: adb forward Protocol:HostPort Protocol:TargetPort

Here is a netcat based example, which I tried on the Emulator and HTC Desire (Rooted & Running Cynogen Mod 7).

From Host (GNU/Linux PC):
$ adb forward tcp:12345 tcp:12346
$ nc 12345

From Target (after adb shell):
# nc -l -p 12346

whatever string typed on target will appear on host and vice versa. This can be used to forward some command from target to host, etc ..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: