topgun741
topgun741

Reputation: 145

Android: Connecting to home server outside of home wifi

I am currently working on an android app that communicates with my home server. The goal of the app is to communicate with the server and display a list of names that are on the server. This all works fine when my phone is connected to my home wifi, but, when I switch to the mobile network or go to another wifi location the app can not display the names. In my code, I am using a string to store the ipv4 address to my home server like this:

String server_url = "http://my home server ipv4 address/getarrayinfo.php";

I tried adding my default gateway into the string like this:

String server_url = "http://my default gateway address/my home server ipv4 address/getarrayinfo.php";

But this did not work. What am I missing here?

P.S. I am using android volley to communicate over the network.

Upvotes: 0

Views: 731

Answers (1)

TJ_
TJ_

Reputation: 368

This isn't really the correct place for this question as it most likely has nothing to do with Android and is about networking.

My best guess from the small amount of information you have provided is you're hitting the wrong IP from outside of the network.

  1. You need to open a port on your router to point to your "my home server ipv4 address" (lets pretend you choose port #2345 and your home server IP is 192.168.0.100). This is pretty simple and can be setup through 192.168.0.1 or 10.0.0.1 depending on your router. Point a TCP port 2345 to 192.168.0.100.

  2. Find out your home network's IP address. You can easily find that out by going to http://www.whatsmyip.org/ Let's pretend it tells you the IP is 12.23.45.56

  3. Now any time you point a device outside of the network to 12.23.45.56:2345 your router will recognize the communication on that port needs to be forwarded to local address 192.168.0.100. So you now setup your server_url to

String server_url = "http://12.23.45.56:2345/getarrayinfo.php";

I also wanted to mention that your home network probably doesn't have a static IP address - meaning that every time your router restarts it'll get something new that isn't 12.23.45.56, so you'll have to update the code if the router restarts. You can avoid this by paying $10/month to your ISP and having them assign your home a static IP.

Upvotes: 2

Related Questions