This has been asked before, but did not receive a satisfactory answer.
From my Android application, I need to send an HTTP request to a PC attached via USB. Typically, communication using ADB is one-way, from PC to Android.
As mentioned in the answers to the aforementioned duplicate, this has been done before: Android Usb Port Forwarding. If I really needed to, I could just download this app and botch it, but I'd much rather implement this within my own app.
Any ideas?
If the Android phone supports USB tethering:
Now a web server running on the PC can be sent HTTP requests with this setup.
It is not actually the communication which is one way, but the ability initiate connections.
To do this with standard android functionality, you will conceptually have to tunnel the device-initiated connections through an existing PC-initiated connection. For example, using off the shelf tools:
You don't actually have to use SSH, it's just that this packages up the pieces ready to use.
As an alternative idea, some Android devices which support USB tethering to provide mobile network service to a PC implicitly end up creating a bi-directional IP network over the usb cable, which you can use for other purposes. But be very careful that you don't accidentally route all the PC's network traffic through the phone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With