I have a server running on an Android emulator, it's listening on localhost:SERVER_PORT
(let's say 6789 in this example). I also have a client app on my emulator that sends a string to localhost:SERVER_PORT
(localhost:6789
) and in return gets another string.
Now I was wondering how I could access the server from the host (a Mac). I read up on https://developer.android.com/studio/run/emulator-networking and tried the following
$ nc localhost 5554
@ redir add tcp:5000:6789
@ exit
$ nc localhost 5000 (nothing happens)
$ nc localhost 6789 (nothing happens)
where EMULATOR_PORT = 5554
, SERVER_PORT = 6789
, HOST_MAPPED_PORT = 5000
.
I also tried running ifconfig locally on the mac, but I got way too many interfaces and didn't know which one to try (I have lo0, en0, p2p0, awdl0, en1, en2, bridge0, utun0,1,2
).
So how exactly can I achieve this? The expected behavior (I think) would be:
$ nc some_ip server_port
@ type_in_a_string
@ get_a_string_from_server