I am trying to debug my visual studio 2012 asp.net project from my phone and have followed all steps here and here.
However none of them work, can't even connect from my other laptop. When I add my public IP or use * IISExpress doesnt even seem to pick up on it (Can't find it in IISExpress->show all applications). But When I used my local IP at least it showed up there and I could connect to it from my own computer, but no other computer/phone.
The cmd commands are successful, I add the extra binding, I open the firewall. Dont know what is wrong.
Which IP (local/public) should I use? what should I type in as URL when I want to test it? I am trying http://IP:port and http://IP:port/Default.aspx.
EDIT: Using this solution I got it to work on my laptop, however I still can not get it to work on my phone.
Basically, the points mentioned in the links you have cited are enough for enabling communication with the phone. But here is one point to make sure (since you have not mentioned it): You have to make sure that both the server and the clients (in your case, the machine that runs the visual studio and your phone and the other laptop) are on the same wireless network. To find out the IP that your server/development machine is currently using, you can issue ipconfig command in cmd and look at the Wireless Network Adapter IPV4 address. For example, if your laptop IP address is 192.168.1.2, you should use http://192.168.1.2:8080/Default.aspx (assuming that your site runs on the port 8080).
You use the local IP if you're on the same network as your server (for example, use WiFi on your phone and join the same network that your server is on).
You use the public IP if the device is outside your network, and you have to configure the firewall to forward the correct ports to the local IP. That's NAT traversal. This would be if you're using the phone's cellular data connection, or you're using a WiFi or wired network that's different from the one your server is on.
Your URL should always be of the format <protocol>://<IP or DNS name>:<port>/<path>. However, you can omit the IP (and the colon) if you're using HTTP on port 80, or HTTPS on port 443. And you can omit the path if you're accessing the root of the site, and your site has a page correctly configured for the root (either via default document in IIS, or route defaults if you're using routing features).
Related
I want to connect to a server on my local network (10.134.0.178:80). The ip address of my machine is 10.134.3.12 and the ip address of the emulator Wi-Fi is 192.168.232.2.
Now I found out that you have to use 10.0.2.2 to connect to a server on your local machine. But the server isn't running on my local machine - instead it is a separate instace on my LAN.
My local machine can reach and ping the server without problems. The emulator not, but the emulator has internet access. So I can access e.g. www.google.com.
How can I connect the emulator with the server? The shown redirection rules only apply on port level. So how is this meant to be used? Other solutions only talk about a local server. Only one is talking about a similar case, but this is not working for me (no connection)
netsh interface portproxy add v4tov4 listenport=80 connectport=80 connectaddress=10.134.0.178
Additionally, I have to switch server instances (different ips/ports/addresses). So how can I use the Android Emulator in this case? To which address should the webservice calls be made? 10.0.2.2 or 10.134.0.178?
Hmmm, well, your Android app should connect to the server's address/port as it appears to the host machine running the Android emulator. I have a web server on my LAN and my emulator can access it directly. Start with pointing Chrome in your emulator at a web server on your LAN (assuming you have one on there somewhere) - if the server is on 10.134.0.178:80 then just type 10.134.0.178 in to your Chrome address bar. If that's not working then you need to look and see what's stopping it - any redirection rules getting in the way?
Don't know what the reason was, but the most plausible one is, that the server had a temporal issue. Now I can connect to my server without further changes!
One thing what still didn't work for me was ping, but it is listed under Local networking limitations:
Depending on the environment, the emulator might not be able to support other protocols (such as ICMP, used for "ping"). Currently, the emulator does not support IGMP or multicast.
I have my Laravel backend that I am trying to connect to from android app. my hosts file has
127.0.0.1 my.backend.test
the httpd conf file in my backend is
<VirtualHost *:80>
ServerName my.backend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog /var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
Header set Access-Control-Allow-Origin "http://localhost:4200"
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
I can access http://my.backend.test/api/some-route fine from google ARC but not from my phone. I seem to have to use my local ip address but I dont understand how to set that up.
I tried adding
<VirtualHost 192.168.my.ip:8080>
ServerName my.mobilebackend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog
/var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
to httpd conf and
192.168.my.ip my.mobilebackend.test
to hosts
If I understand correctly : you can access your server from a different machine on the same network (so this is not a firewall problem) but only if you use the name (added in client's hosts file) and not the IP address.
Is your configuration the first virtualhost ? apache search for a ServerName matching the name provided in the query (e.g. the URL), then falls back to the first one, in your case the ubuntu home page.
As a test, what happens if you use
ServerName 192.168.0.1 (i.e. the IP used in the URL)
I think it will work if you access the server by IP address, but not anymore by name
Try this method
ip:port
Example
10.0.2.2:80
Note: Firewalls may cause problems with this. Windows has Microsoft Windows Firewall enabled by default. You may have to disable it
IP address
If you are using an emulator:
10.0.2.2
If you are using a real device:
Connect them into the same network. Either using a WiFi connection or using USB tethering option in your phone.
Find the IP address of your computer by typing ipconfig in cmd (if you are using Windows)
Port
Default port is 80. If you have changed it, use the new one.
OK, Let's first clarify the problem that you are encountering so that my solution will be clearer.
Your problem is that you are hosting a backend locally on your computer and although you are able to access it without a problem on your computer itself, when you try to connect to it from a different device you are unable to access it.
This problem comes from the fact that your website is hosted locally on your computer and is not accessible to the outside world, Therefore your phone which is presumebly on a mobile network, cannot access your backend since your backend is on your own private network and your phone cannot access this private network from its own network, This is due to the fact that generally your router/isp block incoming requests to port 80, so even if you would know your computers public ip address you still would be blocked.
Now that we discussed the problem, lets go through what a solution would entail.
A solution would entail that either both your phone and your computer are on the same network, or you expose your computer to the public internet.
Lets go through some ways to acheive this.
The first and arguably the simplest way to acheive this would be to put your computer and your phone on the same network. This can be acheived by connecting your phone to the same router that provides your computer with internet access. Once you are connected to the same network, all you have to do is instead of using this url http://my.backend.test/api/some-route, replace my.backend.test with the local ip address of your computer so if your computers local ip is 192.168.0.2 then it becomes this http://192.168.0.1/api/some-route and now you will be able to access your backend from your phone.
Note: You may be wondering how do I figure out my computers local ip address? On windows it can be found by going into network settings > right click on your network connection > click properties from the context menu and then look for the field that says ipv4 address, that is your local ip. On mac you can find it by going to System Preferences > Network > clicking on the connection that has a green dot next to it > Then underneath the status label you will see the current local ip address that you are connected to.
Solution #1 is great if you don't mind going through the hassle of connecting your phone to the same network as your computer, but lets say its a pain, or impracticle for various reasons like lack of wifi etc or its just that you want your phone to be able to access the computer from Anywhere and no matter what network it is on If this is the case, solution 2 is for you.
We will enable access to your computers localhost to the entire internet by using reverse tunneling software, in our case one of the most popular choices is Ngrok, available here. What Ngrok does is it creates a tunnel to your local host and assigns it a publicly accessible domain such as yourapp.ngrok.io which you can use in place of my.backend.test to access your application from anywhere. So once you enable Ngrok you just replace http://my.backend.test/api/some-route with http://yourNgrokAppDomainName.ngrok.io/api/some-route and you will then be able to access your backend from your phone from anywhere no matter which network you are on.
In summary these are two ways for you to access your backend that is on your computer from a phone. Hope it helps.
volley is not working when i want to fetch data from a system on my local network.
where URL is like http://192.168.x.x/data.php
it works well on emulator but not on a real device. it show a time our error.
even i tried setting a maximum time our and retry policy. but in vain.
There are two ways to solve this:
a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.
forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.
c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)
see How can I access my localhost from my Android device? for other ideas
In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.
In second option, the dns will give a tool for auto ip updation :)
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.
I am struggling with this for three days now. It is an android client application that connects to the server AIR application through Wifi on local network.
I need my application to connect to the server every time it is launched without asking the user to enter local IP, in case it changed.
It seems there are many ways to make sure the connection is successful, but I want to make sure I can go without the help of RTMFP or PHP or SharedObject stuff.
I am able to get local IP using NetworkInterface and NetworkInfo ANE from Android client. Then I use the variable to
mySocket.connect(ipAddress, 8888);
But there is a problem:
1) When debugging on Android via Wifi
The detected IP 192.168.137.2
2) When debugging on Flash, on computer
The detected IP 192.168.137.3
So, the local IPs are not the same. So client fails to connect. Everything works perfect, if I manually set that IP, but I need a code that works, even if the IP on local network changed.
As I mentioned making a textInput field in case IP changed and ask the user manually enter IP is not an option.
My question is why using "localhost" as host parameter of socket.connect(host, port) does not work? If it did, there would be no need for detecting local IP at all. "localhost" works for me only if the client is running on computer, but not Android.
Is it the problem with Security Policy file? if so, I have no idea how to use that. I can't find any tutorial on that.
You have two devices
1. Android device running an app and acting as a client
2. Computer running an AIR app and acting as a server
Each of those devices will have it's own IP address on the network. In your case android device IP is 192.168.137.2, and computer IP is 192.168.137.3.
In order for client to connect to server there must to be some means of delivering server IP to the client. Normally for an app like this you enter server IP address manually in settings, or have one central place available on the net where server registers it's IP address and client fetches the address from there.
Since you don't want to use any of these options the last resort would be implementing local area network scanning. Where you scan all the segment 192.168.137.* and search for opened port reserved for server. That of course is not good implementation but could work if project is for your own use.
Lastly "localhost" is name mapped to loopback IP 127.0.0.1 which is special address and is used to connect to the same device app is running on. In your case if android app is connecting to localhost it is trying to connect to the android device itself.