How to access the localhost via android mobile device? - android

I have a asp.net development server(localhost). I want to access the localhost through my android mobile phone(Sony Ericsson XPERIA). Because I have some web service methods that I want to access. I have done it using the emulator(by giving 10.0.2.2:portNo). But I don't know how to access the localhost via the mobile device.
Your help is much appreciated.
Thank You
Update: - 14-09-2012
Guyz I really need your help on this issue.....please help me.. I have a wireless router and my laptop is connected to that, and also my laptop has a static ip given to it.
I have an android phone and it also connected to the wireless router perfectly. And my web site is hosted in IIS7 and it is assigned with a port.
What I need is to access the web services resides in the web site through my android device(using the application).
I have attempted many times giving laptop IP(static IP) and 10.0.2.2 IP also. But none works. And I am really confused now.
If you know any complete tutorials or if you did this before please post it. Your help on this is really appreciated guyz. (please ignore my English if its wrong) Thank you.

You have to change the path that you have given while accessing your
Web Service.
Replace localhost by your own ip address.
You can fetch your ip address through cmd.
goto cmd and type ipconfig.

If your mobile phone and your web server are on the same WiFi network, you can do as was suggested in other comments - figure out the IP address of your development server using the ipconfig command and then use that address on your phone. Note that you may need to modify the firewall settings on your development server to allow incoming connections.
However, if your mobile phone is on 3G or the devices are just not on the same network, things get more complicated because you probably do not have a public IP on your development server and the devices won't be able to see each other.
In that case you either need to reconfigure your development server's local router (google for instructions on "port forwarding") or use a tool like https://pagekite.net/ (disclaimer: I wrote that!) to give your development server presence on the public Internet.
Good luck!

Simply visit 10.0.2.2 in your Android-browser. If this does'nt work, disable your firewall aswell.

You need to connect your Android Device ( Phone or Tablet ) via WiFi Connection with your local network.
Once the connection is establish, you can check the connection in browser by opening url http://xx.xx.xx.xx:portNo ( as answer by EvdTempel )

you need to set address as "10.0.2.2:portNr"
portNr = the given port by ASP.NET Development Server

Hey I had the same issue and resolved it form the information I found at https://forums.adobe.com/thread/1109558
use the 4 answer "4. Re: How to access localhost on ASP.NET Website from Android device"
worked for me :)

Simply visit http://your-system-ip-address/your-site name.
If it does not work then disable your firewall as well.

Related

Unable to connect to an external database [duplicate]

I try to browse localhost on my HTC Magic. I have connected my device with Eclipse via USB. When browsing http://10.0.2.2 I get "Page not available". I remember, some days ago it worked.
But on the emulator I am able to browse localhost
Any ideas?
Easier way to check is in browser of emulator type 10.0.2.2 instead of localhost.
I use my local ip for that i.e. 192.168.0.1 and it works.
to access localhost on emulator: 10.0.2.2. However this may not always work for example if you have something other than a web server such as XMPP server.
assuming that you're on the same wireless network...
find your local ip (should be something 192.168.1.x) - go to the command line and type 'ipconfig' to get this. where x is the assigned local ip of the server machine.
use your local ip for your android device to connect to your localhost.
it worked for me.
If you want to access a server running on your PC from your Android device via your wireless network, first run the command ipconfig on your PC (use run (Windows logo + R), cmd, ipconfig).
Note the IPv4 address: (it should be 192.168.0.x) for some x. Use this as the server IP address, together with the port number, e.g. 192.168.0.7:8080, in your code.
Your Android device will then access the server via your wireless network router.
I needed to see localhost on my android device as well (Samsung S3) as I was developing a Java Web-application.
By far the fastest and easiest way is to go to this link and follow instructions: https://developer.chrome.com/devtools/docs/remote-debugging
* Note: You have to use Google Chrome.*
My summary of the above link:
Connect PC with Phone over USB.
Turn on Phone's "Developer options" from Settings
Go to about:inspect URL in PC's browser
Check "Discover USB Devices" (forward Ports if you are using them in your web-application)
Copy/paste localhost required link to text field in browser and click Open.
Piece of cake
You can get a public URL for your server running on a specific port on localhost.
At my work place I could access the local server by using the local IP address of my machine in the app, as most of the other answers suggest. But at home I wasn't able to do that for some reason. After trying many answers and spending many hours, I came across https://ngrok.com. It is pretty straight forward. Just download it from within the folder do:
ngrok portnumber
( from command prompt in windows)
./ngrok portnumber
(from terminal in linux)
This will give you a public URL for your local server running on that port number on localhost. You can include in your app and debug it using that URL.
You can securely expose a local web server to the internet and capture all traffic for detailed inspection. You can share the URL with your colleague developer also who might be working remotely and can debug the App/Server interaction.
Hope this saves someone's time someday.
Combining a few of the answers above plus one other additional item solved the problem for me.
As mentioned above, turn your firewall off [add a specific rule allowing the incoming connections to the port once you've successfully connected]
Find you IP address via ipconfig as mentioned above
Verify that your webserver is binding to the ip address found above and not just 127.0.0.1. Test this locally by browsing to the ip address and port. E.g. 192.168.1.113:8888. If it's not, find a solution. E.g. https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/z4rtqkKO2hg
Now test it out on your Android device. Note that I also turned off my data connection and exclusively used a wifi connection on my Android.
Mac OSX Users
If your phone and laptop are on the same wifi:
Go to System Preferences > Network to obtain your IP address
On your mobile browser, type [your IP address]:3000 to access localhost:3000
e.g. 12.45.123.456:3000
If your localhost is not running on the default HTTP port(which is port 80), you need to specify the port in your url to something that corresponds to the port on which your localhost is running. E.g. If your localhost is running on, say port 85, Your url should be
http://10.0.2.2:85
For the mac user:
I have worked on this problem for one afternoon until I realized the Xampp I used was not the real "Xampp" It was Xampp VM which runs itself based on a Linux virtual machine. That made it not running on localhost, instead, another IP. I installed the real Xampp and run my local server on localhost and then just access it with the IP of my mac.
Hope this will help someone.
If your firewall is on, turn it off and use IPv4 to test your app in the actual device, then test your application.
I had similar issue but I could not resolve it using static ip address or changing firewall settings. I found a useful utility which can be configured in a minute.
We can host our local web server on cloud for free. On exposing it on cloud we get a different URL which we can use instead of localhost and access the webserver from anywhere.
The utility is ngrok https://ngrok.com/download
Steps:
Signup
Download
Extract the file and double click to run it, this will open a command prompt
Type "ngrok.exe http 80" without quotes to host for example XAMPP apache server which runs on port 80.
Copy the new url name generated on the cmd prompt for e.g. if it is like this "fafb42f.ngrok.io"
URL like : http://localhost/php/test.php
Should be modified like this : http://fafb42f.ngrok.io/php/test.php
Now this URL can be accessed from phone.
I use testproxy to do this.
npm install testproxy
testproxy http://10.0.2.2
You then get the url (and QR code) you can access on your mobile device. It even works with virtual machines you can't reach by just entering the IP of your dev machine.
I used ngrok but now it need registration and it also has a connections request limit. Now I'm using LocalTunnel and so far it's much better.

Cannot browse site hosted on local machine from a mobile

I generated empty backbone application from backbone-generator on my OS X 10.9.1. Then changed the connect hostname in Gruntfile.js to '0.0.0.0' and start the app.
The issue is that I cannot access the application from Android connected to the same home wifi network. I know that my local machine ip is 192.168.1.101. So, I typed in a mobile browser 192.168.1.101:9000 but nothing is loaded.
I have found several similar questions on SO:
How to browse localhost on android device?
Android cannot access localhost?
But the answers did not help me and I cannot comment on them because of my low reputation.
Could anybody help with this issue and say what I'm missing?
It turned out that the issue reason was in the router wifi settings. The "WDS Settings" was disabled and to let devices communicate over network it should be enabled.
Questions that you reported deal with a local http server running on Android, in your case the application is running on your local machine, so it is necessary that your local machine and Android phone have IP addresses in the same subnet.
If you need to assign an IP_ADDRESS to your local machine (wi-fi interface), you can run in the Terminal
sudo ipconfig set en1 INFORM IP_ADDRESS
it may be useful for development purpose.

Access a Tomcat local server using android device

I have a Tomcat server running on Localhost. My app can access it in the emulator using 10.0.0.2:8080. But when I connect a device it can't access the server.
I've seen some similar questions but couldn't get this working. can someone give me the steps on what to do?
we use 10.0.2.2:8081 because 127.0.0.1 is reserved for the emulator, however, when you need to try the application through a real device you need to change the URL to your PC IP
go to CMD and run ipconfig, look for IPv4 address, this IP you will use it..
add it to the URL for example: http://192.somethin.somthin.somthing:8081/the-location.php
P.S: you should set your firewall off and turn off any antivirus
The device may not be on the same network as the Tomcat server. Does your network provide VPN access? If so, try installing an Android VPN client (Junos Pulse is a good free one). Connect your device to VPN and try again.
10.0.0.2 looks like an internal address. The emulator is likely able to connect because the machine on which it is running is connected to the network. The actual device needs a direct connection as well. VPN should solve that.

Debug webservice from android app in the same network

I'm developing an app for android that consumes a .NET webservice. This part is ok, I've already tested in the vm and my app does call the webservice and do what its supposed to do.
The problem is that i need to test it "live" now. As my app needs bluetooth and other stuff that the emulator can't provide I have to deploy it in my phone and try out.
The real problem is that my webservice is hosted in my computer (not in IIS). How can i connect to the webservice?
I've already set a VPN connection in my computer so that i could be in the same network. The connection was ok and i could ping my computer from my android phone (i downloaded an app for that). But i tried to call the webservice using my computer's ip and it doesn't work.
I use this address on browser: http://192.168.56.1:49365/DataUpload.asmx (where 192.168.56.1 is the ip from my computer and DataUpload.asmx is the name of the webservice)
The name of the webservice is ok and the ip too but i can't see the webservice.
Does anyone knows how to help me? I suppose is something with the port or something like that (MY FIREWALL IS DISABLED).
Thanks in advance.
Almost certainly 192.168.56.1 is your router, this is pretty much the norm. To be sure, go to your computer and use the same address in your browser there as you tried on the phone.
Post your results.
One other thing, you'll have to turn off the 'Cellular' radio in your phone to be sure it only connects via WiFi. Otherwise you'll have to find out what IP address you have at your house and point your phone at that IP and port forward from your router to your local machine.

Accessing intranet in Android emulator

I'm trying to test an intranet site in the Android emulator, but I can't seem to get the emulator to access our intranet. For example, the site I'm trying to access is at http://compass/messages, but trying that page in the browser gives me a Google search result page instead of the intranet site.
I can access the INTERNET with the emulator, but not the INTRANET. I can access the intranet from the host machine, and from the iPhone simulator on the same machine.
I'm assuming there's some sort of weird command line thing I need to do, but I'm pretty clueless...any ideas?
After a tremendous amount of searching with no answer, I was able to access my local dev server by substituting the domain with the ip address. For example, instead of:
http://compass/messages
use this (with your server's IP address)
http://172.33.22.1/messages
It works in the Android emulator browser, and also from a WebView in the app in the emulator. I don't know why this works, but it does for me. Hope it helps someone else.
I was having the same problem and I wasn't been able to find any solution anywhere. What I finally did (after playing around with port forwarding) was to use ssh to create a tunnel to the remote machine:
ssh -L 5555:localhost:5555 10.0.1.14
This should allow you to connect to the local machine's IP address in the emulator (10.0.2.2) and reach the other machine in your network (on the specified port).
If anyone has a better solution for accessing the local network from the android emulator I'd love to hear it.
Intranet site may require proxy.
You can set the proxy in Settings
I have solved this problem by following steps:
adb shell
set setprop net.dns 10.10.20.19(your pc's ip)
restart your emulator.

Categories

Resources