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 :)
Related
I downloaded Apache 2.2 from here I know that this is old version but anyway I need it. Then I launched Android emulator and tried to access to server and it worked. I used 10.0.2.2 IP address with 8080 port.
Next, when I try to connect to server using PC on which I launched the server, it works if I provide IPv4 address of PC for example 192.154.1.23:8080.
Well, when I try to connect to server using my physical device (my mobile phone) I can't do that even if I try IPv4 address of my PC with 8080 port. It just tells me about time out.
What should I do to connect to server from my phone?
P.s. I use same WI-FI network on both devices
Solved it.
Well first of all you need to set type of your connection to private and make sure that this is trusted network, for example your home network or your own WI-FI. But you also can do it with public network but this is too risky!!!
Then go to Firewall settings and allow Apache application to communicate with other devices. Choose it in the table of allowed app and features and check the box for private network, then press OK. I recommend to restart Apache server.
That's it! Now you can connect to server using IP address of your PC, on which you installed Apache server, from any device like other PC or mobile phone but you have to be in same local network. If you want to access your server globally you need to ask your ISP (Internet Service Provider) to get static IP address to make it visible in global network.
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).
I have done this successfully before but I am not sure what is going on in this case.
Case that worked:
When I am at home and I connect my computer and my phone to same wifi such that they are on the same network. I can lookup the IP address of my computer and use that IP on my android app to talk to my computer. The local IP is something like 192.168.1.5.
However now I am using a public wifi router. When I connect my computer to wifi I get an IP like 10.10.77.162. When I try to use that IP in my android app to talk to my computer it fails everytime.
What am I doing wrong? Is there an easy way around this?
You have to make sure you forward the port you connect on from your router to your local computer inside your network. Similar to when you open ports for some games such as wow.
Connect your phone the same WiFi network.
Addresses in the 192.168.* and 10.* range aren't globally accessible. They're only used for local networks. If both devices are on the network, they can communicate with each other, but they can't if only one is.
Basically this was due to the fact that I was on a public network in which the router was outside of my control. The router was blocking traffic as one would expect.
I have a Tomcat 7.0 server running on my PC, I access the servlet via Emulator through Url
http://10.0.2.2:8084/MyServer
I am struggling with this for few hours now. I have understood the following steps to achieve this
I need to have a Static IP address? So I am using No-IP Free to covert dynamic IP (I have a dial-up connection) to Static IP.
I need to change the firewall rules in Windows 7. I tried changing Inbound Rules for 'port 8084', but it did not work.
My Question is how to access the same server on my PC via a real Android device having GPRS connection?
Thanks so much.
wifi is the best answer. Get your machine and phone on the same network. If that isn't an option, I'd suggest local tunnel: http://progrium.com/localtunnel/
As long as your server has a public IP address, you'll be fine. The first you should try is to access it from your device using the known IP address and then go for the name resolution, for which DynDNS or No-IP Free will be valid options.
Let's say your pablic IP at any given time is 1.2.3.4, just try
http://1.2.3.4:8084/MyServer
and it should work. Then configure any of the mentioned services and try using the host and domain name.
Firewall rules on your Windows PC and wired/wireless router will both need to allow incoming connections to port 8084.
On the router, set up incoming connections to 8084 to redirect to your Windows PC's local IP address (127.0.0.1). This is called "port forwarding" – look into your router's manual on how to do it.
Once your router forwards incoming port 8084 requests to your Windows machine, you can access it from the outside:
http://your-dynamic-address.com:8084/MyServer
I need to send a POST request to my Visual Studio localhost web server using my Android application. I need to do this for debug purposes.
I don't know how to allow my phone to reach the localhost. I tried to use the computer IP address but it doesn't work. Any help?
You probably need to modify your firewall on your computer to allow incoming connections on the necessary port.
In the end, I used a phone emulator to access locally the localhost server and it worked really well. From the phone, I called the address 10.0.2.2 and it connected to the localhost server.
Your question is mis-stated.
Assuming what you want to do is access a server running on your PC:
You will have the most luck putting the phone and the PC on the same local area (wifi) network.
You may be able to achieve a local network over USB with some tethering solutions.
If the PC and the phone are not on a the same local network, the PC will need to have a globally routable IP address, in order for the phone on it's mobile network to be able to reach it. Many personal ISP solutions do not easily allow for this, due to dynamic IPs, personal routers implementing NAT, or with the IPv4 space being exhausted carrier grade NAT meaning subscribers do not have a unique IPv4 address even temporarily.