Search code examples
javaandroidusbadb

Android Client Application (Possibly using ADB through USB)


Phone Information: Droid Bionic Android 2.3.4 USB Debugging Enabled

I am looking into writing an application for personal use, where I can send data from the client (on the phone) to the server application (on my computer), hopefully through USB. The only suggestions I have found for this using Android 2.3.4 is to use ADB and then to do something with TCP forwarding.

I have wrote a simple server and client application between computers using port 8001, but am having issues getting the client on my android to work with the server piece on my computer. I can create a socket for to talk to my computer (192.168.1.26, 8001), but can't seem to get it to work because the java is different on the android device from the comptuer client I made. Does anybody know of a very simple tutorial or example I can look at for just connecting the client to a server piece? All of the previous examples I have looked at are all complicated.

As for the USB portion, I would hopefully like to be able to get my application to work without going through the network. I have seen things about using "ADB forward tcp:port tcp:port", but am a bit confused on the whole thing. What do I set for the IP address and port number for the socket on the client, and do I leave the server on port 8001? What command do I use through ADB to do this if I wan't to use port 8001?

Thank you


Solution

  • If you want to forward TCP port 8001 on your computer to port 8001 on the phone, you'd use this command:

    adb forward tcp:8001 tcp:8001

    You can change the ports on either the phone or the device, if needed. Documentation for that command is here: http://developer.android.com/guide/developing/tools/adb.html#forwardports

    As for why this shouldn't work -- there's some information missing from your question. These are just standard TCP sockets. The Java version shouldn't make any difference, so I don't understand your problem. The client running on your computer could be written in any language (Ruby, C++, etc.).