Making Http Request to Local Computer from Android Emulator - android

I am using Visual Studio Emulator for Android. I have checked the network settings on my virtual android. My Desktop Adapter is 192.168.0.3 the other is 169.254.80.80.
I have tried in my config all three connections other posts have mentioned. This is not a duplicate because these three do not work.
http://10.0.2.2:52930/api/values/5
http://192.168.0.3:52930/api/values/5
http://169.254.80.80:52930/api/values/5
I have verified my service is running and can be accessed from my local computer with http://localhost:52930/api/values/5
The error for 10.0.2.2 connection and 192.168.0.3 is
{"originalStack":"Error: java.net.ConnectException: failed to connect to /10.0.2.
2 (port 52930): connect failed: ENETUNREACH (Network is unreachable)\n at ZoneAwar
eError (file:///data/data/org.nativescript.Groceries/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:
993:33)\n at onRequestComplete (file:///data/data/org.nativescript.Groceries/files/app/tns_modules/tns-core-modules/http/http-r
equest/http-request.js:44:34)
There is a much longer period of wait (about 2 minutes) before the 169.254.80.80 connection begins to show the above error.
I have disabled the windows firewall. I have no other firewalls. I have allowed Hyper-V application in the firewall just in case.
Any other suggestions?
EDIT
It appears to be an issue with the emulator. I opened up the browser in the emulator and typed in http://headers.jsontest.com
And it appears that it can't access that url. The error the emulators browser is reporting is.
Webpage not available.
The webpage at http://headers.jsontest.com/ could not be loaded because:
net::ERR_NAME_NOT_RESOLVED

Related

Unable to open connection to: localhost/127.0.0.1:5037, due to: java.net.ConnectException: Connection refused: connect

My Android Studio 3.4.1 shows the error below (as in screenshot) when running the app
Unable to open connection to: localhost/127.0.0.1:5037, due to: java.net.ConnectException: Connection refused: connect
I have my android phone connected to my Windows 7 PC, but Android Studio still show the error. I did click on "Restart ADB server" but problem persists.
Thank you
Use 10.0.2.2 to access your actual machine.
When you use the emulator, localhost (127.0.0.1) refers to the device's own loopback service, not the one on your machine as you may expect.
You can use 10.0.2.2 to access your actual machine, it is an alias set up to help in development. You can read more from Here
Also, remember to access localhost from your real device your system and mobile need to connected to the same wifi/network.
I had the similar problem on Ubuntu: but I found out also that my phone keep reconnecting in IDE.
Solution - just to give permission change things to the android studio folder.

Android Emulator No Internet when using tethered iPhone

I've been struggling with this for a couple of days.
My Android Emulator does not have access to the Internet on Mac OS X when I use my iPhone's tethered Internet connection. I often use this connection whenever working on the go, so it's quite frustrating when it doesn't work.
I've tried the following:
Setting DNS and running emulator from command line.
./emulator -avd Pixel_2_API_26 -dns-server 8.8.8.8
Removing network connections except the tethered connection from Mac OS Networking.
Deleting and reinstalling the AVD.
Looking at the logs, the only networking related errors I get are:
D/NetworkMonitor/NetworkAgentInfo [WIFI () - 101]: PROBE_FALLBACK http://www.google.com/gen_204 Probably not a portal: exception java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname
I/qemu-props: start adbd ...
and
D/NetworkMonitor/NetworkAgentInfo [WIFI () - 101]: PROBE_DNS www.google.com 78245ms FAIL
D/NetworkMonitor/NetworkAgentInfo [WIFI () - 101]: PROBE_HTTPS https://www.google.com/generate_204 Probably not a portal: exception java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname
D/ConnectivityService: NetworkAgentInfo [WIFI () - 101] validation failed
D/WifiStateMachine: NETWORK_STATUS_UNWANTED_VALIDATION_FAILED
I feel like the simulator is still trying to use WiFi even though the WiFi device has been removed.

Android Emulator: Can not connect to internet for some apps behind proxy

Purpose: To access the application in emulator through proxy
What I did: Successfully launched emulator and set Burp proxy in emulator network setting. I can access net in browser and some of application (flipkart, imdb) through proxy.
In Burp I set "CA Signed per host certificate" for SSL setting
I'm using: ADB 1.0.31, Android Emulator Version 22.0.4.0
Problem: But some of application which asks authentication first (like evernote, lookout etc) an error occurs saying "There's a problem in internet connection"
Is this problem because of SSL certificate or anything else.

Unable to connect backend server with android emulator

Hi i am developing and android application which communicates with the backed server. I Tested my application inside my Working environment its working fine... I am able to connect to the server and i got the response...
But when i went for testing in my clients environment, i was unable to connect to the back end server.. I used their LAN to access web server...
The problem i am having is Unknown Host name..
Insted of giving the host name i gave the ip address to the host and my application got the response successfully from the server, but if i change the ip address to the DNS i was unable to connect..
I Tried several options
Tried to set the host ip address in Eclipse -> Window -> Preference -> Android -> Launch. but it didnt work.
I Tried to launch the emulator from the command line using the following command
emulator -avd MYAVD -dns-server X.X.X.X
this one also didn't work.
Since my time is limited to deploy i need help.

Getting "Launch error: Failed to connect to remote VM. Connection timed out" when trying to debug my app on my device in android

I tried all the possible options given on net and on this site, but none of them worked.
I am getting:
Launch error: Failed to connect to remote VM. Connection timed out.
when I am trying to debug my application on my mobile device.
the application runs properly with out any issue when I am running normally
I have used at lease these links by now:
How to resolve "Waiting for Debugger" message?
Eclipse issue - Launch error: Failed to connect to remote VM. Connection timed out
Eclipse Error: "Failed to connect to remote VM"
Launch error: Failed to connect to remote VM
https://forums.oracle.com/forums/thread.jspa?threadID=653343
None of the above seem to work.
Go to Window -> Preferences -> General -> Network Connections, and check if there is any proxy set here, change the 'Active Provider' to be 'Direct' and try again.
I dont know why, but this works for me:
First Run(or Debug) your application in an emulator and then Debug the application on the device (without closing the emulator).
let me know if this works for you.
I've been having the same frustrating problem. I finally found something that is working for me: making sure localhosts is being resolved correctly (and really explicitly).
Test to see if it works when your development machine is not connected to the net (no WiFi, no network cables). If it does work under those conditions, then it may be that you need to make sure that addresses are resolving to localhost properly. The messages that DDMS and adb.exe use for debugging and communicating to the VM must properly resolve to localhost on your machine. (Yes, it's odd that other commands using DDMS & adb work just fine but debugging doesn't. Seems that something in DDMS or adb needs to be standardized so they all work under the same conditions.)
If you need to make sure that things are resolving to localhost properly:
1) Make sure that this line is in your /Windows/System32/drivers/etc/hosts [windows] (or etc/hosts [*nix] file:
127.0.0.1 localhost
(you can have any amount of whitespace between "127.0.0.1" and "localhost")
2) If that doesn't work, then you may need to also add your PC's IPv4 address to the hosts file, and resolve it to localhost. (You can find out the IPv4 address for your machine with the ipconfig command.) If, for example, your machine's IPv4 address is 192.168.1.100 then you'd add the line
192.168.1.100 localhost
to your hosts file. (You can add it below the "127.0.0.1 localhost" line in the file.)
I had (1) in my hosts file but it still wasn't working (unless my PC wasn't connected to the net). I tried (2) on a bit of a guess, and that worked for me.
BTW: You can verify that adb (and your emulator if you're running one) is listening on ports by using the netstat -b command. (Note that on Win7 you need admin privileges for the -b option. I open a command window using "Run as Administrator.")
May seem like an obvious answer but make sure you don't have two emulators running - 5554; 5556; ... The debugger has difficulty setting the port when it doesn't know which one to connect to.

Categories

Resources