How to let two apps running on different computer inside android emulator connect

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.comCode 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:4000Code 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

TCP Proxy – port fowarding

I was unable to access my router from the public network or outside my home network. Since I often have to go out and access my network, I wanted to able to able to access my router too. Port 80 was blocked by my ISP so even though i know public ip of my router was unable to access the page.

So I figured out there is a way to forward packets to another machine. for that you have to use iptables, however it may have some glitches, I have not used this.

While searching for this I came across a tcp proxy command as follows

socat tcp-listen:8083,fork tcp:192.168.18.1:80 
also 
socat TCP-LISTEN:8080,fork,reuseaddr TCP:google.com:443Code language: CSS (css)

fork keyword means it can create new thread if there are multiple clients. so I ran this command on raspberry pi which would forward all my traffice on its port 8083 to router page.

This worked on chrome browser but firefox was caught up in some kind of a loop.

References