1. Are you ready for the Galaxy S20? Here is everything we know so far!

ADB reverse and TCP communication

Discussion in 'Android Development' started by mdsousa, Oct 29, 2020.

  1. mdsousa

    mdsousa Newbie
    Thread Starter


    I have Android Studio 4.1, with ubuntu 18.04 in a VMWare Virtual Machine on a Windows 10 laptop. I have connected (using USB3) a Samsung Active 2 Tab up to the laptop (USB3) and Android Studio communicates with it. I can get an app to run on the device from Android Studio and with the help of ADB's command reverse, I can create a server in an Ubuntu terminal in the VM that the app on the device can then read from using Sockets.

    First thing I do is:
    Code (Text):
    1. mike@ubuntu:~$ adb reverse tcp:1234 tcp:1234
    The client code on the device is simple:
    Code (Java):
    2. Socket socket = new Socket(hostname, port);
    3. InputStreamReader input = new InputStreamReader(ocket.getInputStream(), StandardCharsets.UTF_8);
    4. String msg = br.readLine();
    5. Log.i("MESSAGE SAYS: ", msg);
    6. input.close();
    The server in the Ubuntu terminal is even simpler:
    Code (Text):
    2. mike@ubuntu:~$ nc -l 1234
    3. hello
    logcat in Android Studio displays the response the client gets from the server:
    Code (Text):
    1. MESSAGE SAYS: hello
    So my question (whew, sorry about so much blabber above):, is this actually a TCP operation or is adb doing the actual bridging (listening and doing some sort of loopback) with the network traffic? In other words, can USB3 actually have a TCP connection?



Share This Page