• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ADB reverse and TCP communication

mdsousa

Newbie
Oct 17, 2014
14
1
Hi

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:
mike@ubuntu:~$ adb reverse tcp:1234 tcp:1234

The client code on the device is simple:
Java:
Socket socket = new Socket(hostname, port);
InputStreamReader input = new InputStreamReader(ocket.getInputStream(), StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(input);
String msg = br.readLine();
Log.i("MESSAGE SAYS: ", msg);
input.close();

The server in the Ubuntu terminal is even simpler:
Code:
mike@ubuntu:~$ nc -l 1234
hello

logcat in Android Studio displays the response the client gets from the server:
Code:
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?

Thanks...
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones