I know it is possible to forward a port from my develop machine to an Android emulator, but how is this done? I\'ve found the solution on the android-developers site, but I
You can use the adb forward command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:
adb forward tcp:6100 tcp:7100
For example run NanoHTTPD web server on the AVD and then execute this command on the computer:
adb forward tcp:8080 tcp:8080
Open the browser on the computer and navigate the below address:
localhost:8080
http://developer.android.com/tools/help/adb.html#forwardports
To forward a port from your local machine to an Android Emulator, you need to have Telnet enabled. This is done through the Control Panel -> Programs and Features -> Turn Windows features on or off -> scroll down to Telnet Client. Then select it & press Ok. Now from your command prompt (with the Emulator running) you type telnet localhost "EmulatorPortNumber"
. The "EmulatorPortNumber" can be found in the titlebar of the Emulator, in my case it was 5554.
You will now see something similar to this:
Android Console: type 'help' for a list of commands
OK
Here, you want to type with as little as possible typo's, as when you apply the backspace, it will corrupt your command and not accept it. The command you have to use here is redir
. This will let you choose from 3 subcommands:
list list current directions
add add new redirection
del remove existing redirection
The one you need now is add. But you can't use it just like that. Typing redir add
will give you the following line:
KO: bad redirection format, try (tcp|udp):hostport:guestport
This means that you have to specify what kind of port you want to forward (TCP or UDP port), which port on the local machine you want to forward (hostport) & which port you want to set on the Emulator (guestport). So, using a command like this:
redir add udp:1337:12345
forwards the UDP port 1337 on the local machine to port 12345 on the Emulator. Be cautious about deleting redirections, as they might crash your Emulator. You can also simply close the Emulator to remove any redirections. It's easier & safer...
You access your computer's localhost
as 10.0.2.2
from emulator. more details here