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.
Related
Is there a way to access my host machine's network?
Specifically I want to scan host machines network and find devices connected to same network.
In short, you can't. The simulator can only talk to the host machine.
the host must provide the service to access other resources on the network.
previous text:
The android simulator is not on your home or office network.
As this was said before.. there is a small network bridge between the computer and the simulator, can you can access the host computer via the IP 10.0.2.2.
Now to access other machines on the network, or perform a scan, you basically have two choices. either the host give you access via a tunnel.
or you join the network by some other mean.
I am not sure the simulator can open a wifi connection, the device would need to be stubbed. maybe if your computer is connected via LAN cable and your wifi device delegated to the android simulator its possible.
the other choice is to use a VPN, so then every machine connected to the VPN would be on the same network.
your best bet is probably to use a real phone connected to the network via wifi.
You can access your host machine by the IP: 10.0.2.2
I have a Web API Project hosted on my local system (Windows 7) on IIS7.
I am trying to access that Web API or for that matter another website hosted on the same IIS via my android mobile phone and My Mobile phone is connected to local wifi. But this IIS computer is connected to same network via wired LAN. Though I can access my router that is hosted on "xxx.xxx.1.1" IP Address from that computer as well as mobile phone but i am unable to access the IIS website from my mobile phone.
I tried turning off my windows firewall on the IIS computer where this website is running, but this didn't help as well. Although i can access this IIS website via another computer on the same LAN.
I think the issue is related to LAN or wifi but it should not be as the network and router for LAN and wifi are the same.
Need immediate help and how can i solve this.
Thanks
Can you ping your phone from your computer? Or vice-versa?
Access your router configuration and check for any access control setting that might be separating WiFi from LAN.
OK. When it was extremely urgent today, i found the answer myself. It was D link Router problem and here is the solution. Hope this helps others.
Check option Clients isolation in Wireless -> Basic.
If it turned ON - clients from LAN wil not access Wi-Fi clients and vice versa.
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 am trying to deploy and test my application on an android device which is then connected to my laptop with a usb-cable. Now, how can I target a webapp deployed on my laptop ?
knowing that my wifi is down and that I don't have the right to change router configuration to do some IP port forwarding tricks (in case you would like to suggest me to use the mobile network e.g 3G, go on internet and get back in via our router external IP address ==> which is also a little bit heavy given what we want to do here)
According to the android documentation, "the emulator" can use the ip address 10.0.2.2 to access the hosting computer but there is nothing for devices...
thanks in advance guys,
I am implementing a mobile chat application, I am using socket connection for implementing p2p connectivity. My chat is working fine with android devices. My issue is I can connect a device in 3g network or with in the same WiFi network but the connection is not working when a device form outside WiFi try to connect a device in the WiFi network. I know it's because of the local IP of the device assigned by the WiFi. How can I root and connect a device in the WiFi?
Sounds more like a router settings issue, than an app issue (meaning that users of your app would need to do this for their own networks as well).
Your wifi router needs to know how to forward communication to your device. So say that your app is connecting on port 1234, then you need to tell your router to forward communication from the outside on port 1234 to the internal IP of your phone in your wifi network.
The phone that is outside of the network should target your network's external IP and port 1234.
Sajan, your issue is not only an IP mapping issue, but also a NAT traversal issue. It is not always possible to punch holes in NATs. And when it is, it must be done with some sophisticated techniques including a super peer located outside of your wifi/lan which will read the translated address from your inside peer.
Unless you are using UDP and the NAT is friendly, it is not possible to send TCP communication directly to the inside peer. In most case, you'll have to check what is possible with the NAT, and if there is something possible, you'll need to perform mapping prediction and tell both peer to attempt com on predicted IP addresses.
That's valid if you don't want you users to have to configure their NATs. And even in that case, such configuration will not always be enough (if there are cascades of NATs, or proxies for example).