One of my android application listens to incoming connections from a desktop application which then sends data to it. The desktop application client only runs on a macOS or a windows. The android application during my software development or debugging runs inside emulator on my development machine which is Ubuntu. So how do I test my android application and the client without changing my development machine OS/Ubuntu. basically you need SSH on both machines to make it work. With SSJ we can open a tunnel between the two computers.
ssh -NL 4444:localhost:8000 ahmed@myzbook.com
Code language: CSS (css)
I run the above command on my macOS where the desktop application is running . This will create a tunnel between macOS and Ubuntu dev machine. Now my desktop application client connects to 127.0.0.1 port 4444 and this connection goes and hits 127.0.0.1:8000 on Ubuntu machine. But this is not yet enough. We need to forward port 127.0.0.1:8000 to emulator-IP:port-android-app-is-listening-on/ for that.
adb forward tcp:8000 tcp:4000
Code language: CSS (css)
Assuming my android app in emulator on Ubuntu is listing on port 4000. the above command will redirect 127.0.0.1:8000 to emulator:4000. You may also use socat tool instead of adb