How can I forward my localhost IP-Address to an Android Emulator?
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...
How to connect to my http://localhost web server from Android Emulator
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead.
You can read more from here.
How do you connect localhost in the Android emulator?
Thanks, @lampShaded for your answer.
In your API/URL directly use http://10.0.2.2:[your port]/
and under emulator setting add the proxy address as 10.0.2.2 with the port number. For more, you can visit: https://developer.android.com/studio/run/emulator-networking.html
How can I access my localhost from my Android device?
USB doesn't provide network to mobile device.
If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not localhost
and not 127.0.0.1
).
To find out the IP address of your desktop:
- type into the command line
ipconfig
(Windows) orifconfig
(Unix)- on Linux the one-liner
ifconfig | grep "inet " | grep -v 127.0.0.1
will yield only the important stuff - there's a bunch of suggestions on how to have a similar output on Windows
- on Linux the one-liner
- there's going to be a bunch of IP's
- try all of them (except the forementioned
localhost
and127.0.0.1
)
If your phone is connected to the mobile network, then things are going to be harder.
Either go hardcore:
- first find out your router external IP address (https://www.google.de/search?q=myip)
- then, on the router, forward some port to
<your desktop IP>:<server port number>
- finally use the external IP address and forwarded port
Otherwise use something like xip.io or ngrok.
NOTE: The ifconfig
command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:
ip address
The above ip command can be abbreviated to:
ip a
If you still prefer to use ifconfig
as part of your daily sys admin routine, you can easily install it as part of the net-tools
package.
apt-get install net-tools
Reference is here
Port forwarding local server to Expo android emulator
You can access host machine from inside the android emulator by going to the address 10.0.2.2 inside the emulator.
For example if you have a web service accessible on localhost:8080
on your local machine, you can access the same by typing
http://10.0.2.2:8080
from inside the emulator. More details about emulator networking you can read in the official documentation
How to connect to the localhost of an Android emulator?
You can do that with adb forward
. See port forwarding
adb forward tcp:3000 tcp:3000
Then on your computer you can connect to http://localhost:3000
and it will be routed to port 3000 of the emulator.
Android Emulator, Forward port to public interface, not localhost
I've successfully used stcppipe
to achive that. It just forward TCP connections to any of local machine interfaces to a specific IP address (in your case it will be localhost
).
It can be download from Luigi Auriemma
Run it with:
stcppipe.exe localhost port port
Regards.
Connection to LocalHost/10.0.2.2 from Android Emulator timed out
I have figured out the reason why it was not working.
There were two issues --
The IP Address was not correct. So I changed the IP Address from
10.0.2.2
to theIPv4
address - which can be obtained on windows by typeingipconfig
in the command prompt and see link for linux.Also the port number 8080 was not correct. I have set my own port number in
httpd.conf
file, like##Listen 12.34.56.78:8383Listen 0.0.0.0:8383Listen [::0]:8383##
, under Apache and I used the same.
After changing both and re-starting the WAMP server, it worked like a charm.
Related Topics
Set Starting Height of Collapsingtoolbarlayout
No Repository Found Error in Installing Adt in Eclipse Indigo
Linearlayout Height in Oncreate Is 0
How to Programmatically Pair a Bluetooth Device on Android
How to Set Android Tablayout in The Bottom of The Screen
How to Find Out Carrier's Name in Android
Inconsistency Detected in Recyclerview, How to Change Contents of Recyclerview While Scrolling
Android 4.4.2 - Java.Lang.Runtimeexception: Performing Stop of Activity That Is Not Resumed
How to Place App Icon on Launcher Home Screen
How to Use Standard Attribute Android:Text in My Custom View
Apply Two Different Font Styles to a Textview
How to Know If Android Talkback Is Active
Imageview Adjustviewbounds Not Working
End Incoming Call Programmatically
Gradle Project Sync Failing After Google Announced The New Sdk Versioning System