Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I'm trying to access a web server running on the Android emulator from my machine. I know the reverse i.e., how to access the server running on my local machine from the Android emulator (using 10.0.2.2). I have searched a lot about this stuff but couldn't get any relevant information.

When the server is up and running inside the emulator I can access it using 10.0.2.15:portNumber. I can do a telnet to the emulator, but I wonder how that will be helpful. Any suggestions on how to get connected to the web server running inside the emulator?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You need to create a port forwarding to your Android device. This can be done with ADB.

adb forward <local> <remote> - forward socket connections
                                 forward specs are one of: 
                                   tcp:<port>
                                   localabstract:<unix domain socket name>
                                   localreserved:<unix domain socket name>
                                   localfilesystem:<unix domain socket name>
                                   dev:<character device name>
                                   jdwp:<process pid> (remote only)

For example: run adb forward tcp:12345 tcp:23456 and then use the URI http://localhost:12345 to access the server running on port 23456 in the emulator. Note that some ports are reserved for Android and some can only be used after rooting, so I'd suggest using high ports (>20000) if you can.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.