-1

I am building an android application for one of my university courses. I have a localhost server running on my laptop using xampp. The android application running on my phone has to connect to the localhost to get data from a MySQL database (through a php script). I use HTTPClient in my code to connect to the server. The code works fine, but because my ip address changes I need to keep changing the url in HTTPpost. My question is how can I get a static ip address? I need this to work anywhere I am, for example I will be coding and testing at home, but I will eventually have to show a working application at university. Here is my HTTP code:

private String[] url = new String[] { "http://172.24.25.204:80/comp5615/select.php" };
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url[0]);
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(param));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            //read content
            is =  httpEntity.getContent();  
            result = convertStreamToString(is);
        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection "+e.toString());
        }
Siddharth
  • 9,349
  • 16
  • 86
  • 148
pixie
  • 151
  • 2
  • 10

2 Answers2

2

Your question is not related to android, its more related to how to get static ip address so your local pc can act as server and you can connect anytime from anywhere.

Back in days when i was hosting few test websites on my pc i had same problem. And i was using no-ip.com service to have all-time connection. There is also dyn.com and opendns.com

Basically what you do is install their software and keep it active in your system try, than connect to their server and they will give you ip or subdomain name which you use to connect instead your dynamic ip. And their software communicate all the time with your ip and keep your server online even when ip is changed.

lonerunner
  • 1,282
  • 6
  • 31
  • 70
  • I did as you suggested and got an ip from no-ip.com..but how do I now connect to localhost? When I use the assigned ip address it doesn't work. – pixie Oct 05 '12 at 09:23
  • you need to download and install their software and keep it active. Software will connect your dynamic ip with static one they gave you. – lonerunner Oct 05 '12 at 13:23
0
you can get Static IP Address in browser as well as programmability in application. 
this is url return the static IP adress 

"http://api.exip.org/?call=ip"

in android normally we request above mention url and getting response  of it
javid piprani
  • 1,965
  • 1
  • 12
  • 10