5

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?

10

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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