I am using an emulator and a local server to run a certain app.
Because it is a school project I need to show the app to a tester and then the app would be checked by a different tester without me showing it.
As the app needs to call the local server it needs to know the ip of the machine running the server.
How can the emulator gain the ip of the machine running it?
Tried using LocalHost and 127.0.0.1 instead if the ip address 10.0.0.10 that I had but it didn't work.
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.
Related
Started a local server in my computer with IP 127.0.0.1 listening on port 3000.
However, I am unable to access it via my android app when I run the emulator on android studio. I got a timeout error from my app's networking library, so it is not making connection.
Use the IP address 10.0.2.2. You can read more at here.
On each Android emulator Android Studio runs a router for it in order to isolate the emulated device from your development system. Thus in order to access a local server running on your development system (your laptop, desktop, etc) you must use the special IP of 10.0.2.2 and the port the server is listening on. To learn more read this page.
I am making an application that needs to access the server database.
But since its still in the early stage, I have to delete the database quite often which is a problem because its used for other web applications too.
So I was thinking if I could test my application against my localhost database it would make it much easier for me.
I tried a few solutions on stack overflow but they didn't work for me so here is my problem.
I have lamp setup on my system.
In my browser, I can access localhost using 127.0.0.1 but if I try the same thing on my phone's browser it shows that the connection was refused.
Both my laptop and phone are connected to the same wifi network.
Is there some permission I have to provide that I am not aware of?
your 127.0.0.1 refers to your desktop.
Find out the local ip of your desktop (example 192.168.0.2) and then use that ip on your mobile browser
You should try to access to your laptop by using its IP address.
If your laptop is running on Windows, run the command ipconfig from a Command Prompt Window and then use the ip address the command returned on your phone's browser.
This should work.
In my android app users should type their personal datas and it should be sent to remote database. In order to do that I have created PHP script and AsyncTask class and all the other necessary things. When I run the app on localhost, everything works perfectly.
Here is the line when PHP script is called from android app
insert.execute("http://10.0.2.2/registerApp.php");
My question is, what IP adress should I type instead of 10.0.2.2 in order tu run my app successfully on real device, not on emulator ??
I am confused, first thing that crossed my mind was that I should type IP adress of my phone device where I am gonna test the app, but then I thought what is gonna happen if I take some other phone device which has different IP adress?
My question is, what IP adress should I type instead of 10.0.2.2 in order tu run my app successfully on real device, not on emulator ??
The IP address of the 'server' hosting the PHP script.
The address 10.0.2.2 (when used on an emulator) is translated to be the localhost address of the PC which the emulator is running on.
If you take the emulator out of the equation, and assuming you're connecting to the 'server' using wired or wireless connection, then you need to use the actual IP address of the PC.
I am trying to implement an Android application in Windows 7 using Eclipse. I am trying to connect the Android simulator to the local test server in my company, but for some reason, it cannot connect to the test server.
If there is any settings or configurations for this, please let me know.
I have tried to do the same from a MAC machine using iPhone emulator and I am facing the same problem. How would this emulator connect to the local servers in my company as currently it all goes to live servers? What configurations are required to be done on the simulators, and how?
If I try to connect to the test server from normal Windows machine browser, I am able to successfully connect to it through the web browser; but when I try to do the same from the Android emulator browser, it cannot connect to it.
The emulator points to the live network and not the local network in my company. This is strange and I know that I need to do some settings for it, but I am not sure where these settings are done and how.
If accessing local computer:
http://localhost:8080/MyLocalServer.html // URL to use in computer browser
http://10.0.2.2:8080/MyLocalServere.html // URL to use in emulator browser
Also try using a local IP to connect to any local servers. Do not use host names.
Dont:
http://mylocalserver.org/
Do:
http://192.168.1.125:portnumber
You have to set up IP-based hosts instead of name-based.
Emulator its - VM. This use virtual network connection. I think you need before chech this connection (this connection may bee stay as NAT, Breedge, Native IP adress, Proxy).
Since you do not work iPhone emulator, most likely you, IP adress virtual network connectionб which uses Emulator, does not match the address area of the local network, and routing occurs
This may help you...
Taken from the android docs:
If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.
http://developer.android.com/guide/faq/commontasks.html#localhostalias
I'm running a service through ASP.net/Visual Studio that's being developed in conjunction with an Android app. When I run the service through VS, it's accessible at http://localhost:13980/ but not http://127.0.0.1:13980/ (which gives a "bad request - invalid hostname" 400 error). Obviously, I can't tell the Android app to look for a service at "localhost" since that'll be pointing at itself.
I understand (according to this page) that the Android emulator treats 10.0.2.2 as a pass-through IP address to the host machine's 127.0.0.1, so it would stand to reason that everything would come together if I a) got localhost to be properly exposed through 127.0.0.1, and b) changed the target address in the app from localhost:port to 10.0.2.2:port.
How would I go about doing part A? I'm running Windows 8.1 Pro, Visual Studio 2012, and the project in question is targeting .NET 4.5.
Thanks!
You have two options:
Run the web service under IIS instead of VS Cassini. This way you can bind the web service to your local network's IP address, e.g. http://10.0.2.2:8081
Modify the hosts file on your Android emulator to redirect localhost to your computer's IP address
The second one isn't a great solution. It may cause some conflicts with the OS and I'm not even sure Cassini would still even serve the request. Visual Studio's in-built web server (Cassini) only listens to local requests, so option (1) really is the most flexible. Plus, since you have W8 Pro IIS is already built-in.
The IP address 10.0.2.2 IP maps to the the 127.0.0.1 IP address, not to localhost.
From the emulator, connect to 10.0.2.2, and then host your site on 127.0.0.1 instead of localhost. That should work.
Use the IP address 10.0.2.2 instead. See this:
How to connect to my http://localhost web server from Android Emulator in Eclipse