Background
I've been search AE, SO and Google for many hours and found many examples of people wanting to connect their PC to the emulator. I've also run across some that wish to connect their device to their server on a PC. I want to connect my device, to an emulator running on a PC. I've tried the examples given in the documentation but I still haven't gotten this to work.
I would like to have my device (real device, Nexus 7) create a Hotspot that my PC is connected to. In the PC, an emulator is running that has a socket open on port 40000. I'm getting ECONNREFUSED errors when trying to connect my device to the emulator. Here's what I'm doing:
Connecting device to emulator (through PC)
Device tries to create a Socket connection to the emulator through the PC. The IP of my PC is 192.168.43.198 so that is what the device use as destination IP. The connection fails however, with an ECONNREFUSED message.
Forwarding using ADB and telnet
On the PC I've tried to forward port 40000 to the emulator using:
adb forward tcp:40000 tcp:40000
and
redir add tcp:40000:40000
over telnet to the emulator.
When running the adb forward command I get a listening port on the PC as such:
TCP 127.0.0.1:40000 0.0.0.0:0 LISTENING
.
Notice that the listening IP is 127.0.0.1.
When running the redir
command, I can see no listening port using netstat.
Testing connection from device to PC
To test the connection "parts", I've used SocketTest
(http://sourceforge.net/projects/sockettest/) on my PC.
If I use it as a server, listening on port 40000. Then my device connects to it just fine using 192.168.43.198:40000.
Testing connection from PC to emulator
When using SocketTest as a client to connect to 127.0.0.1:40000 it also connects fine to the emulator.
However, when using the external IP: 192.168.43.198, SocketTest also gets connection refused!
Possible problems
It seems to me that my PC doesn't realise it should route 192.168.43.198:40000 to 127.0.0.1:40000 although the commands I've entered claim to do so in the docs (http://developer.android.com/tools/devices/emulator.html#redirection and http://developer.android.com/tools/help/adb.html#forwardports)
Firewall is turned off.