1. Download our Official Android App: Forums for Android!

Apps Using my Android app. on a different network?

Discussion in 'Android Development' started by simhamed, May 9, 2012.

  1. simhamed

    simhamed Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    8
    Joined:
    May 7, 2012

    May 7, 2012
    8
    0
    25
    Student
    France
    Hello guys!
    I'm not here for the code but more for your ideas/suggestions.

    So here's the problem : I managed to make this Android application that can show my DB's records and works just as I wanted.
    The code uses a PHP script to connect with a local mySql database and a JSON parser is also used.
    Of course, the application works perfectly in my internet connexion since I forwarded the port 80 to my computer by loging into my router.

    http://img135.imageshack.us/img135/6646/52938713.png

    Now, I'd like to make it... more global?

    I'd like for example to use this app in my university's network.
    But I can't access the university's router... So how can I use my http://ipaddress/temperature.php script without being able to forward port 80 anymore? And is there any "static" IP adress I can use? (like, not having to change my IP adress on the code everytime I connect to a different network)

    Code (Text):
    1. try{
    2.      //commandes httpClient
    3.      HttpClient httpclient = new DefaultHttpClient();
    4.         HttpPost httppost = new HttpPost("[B]http://81.xx.xxx.xxx/temperature.php[/B]");
    5.         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    6.         HttpResponse response = httpclient.execute(httppost);
    7.         HttpEntity entity = response.getEntity();
    8.         is = entity.getContent();
    9.      }
    10.      catch(Exception e){
    11.       Log.i("taghttppost",""+e.toString());
    12.             Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
    13.        }
    Any ideas guys how to proceed please ?
    Is there a way I can still use my PHP script on any network?

    Thanks in advance for any help!
    Any suggestion is welcome to solve this issue.

    PS : The code used looks a bit like the one here
     

    Advertisement

  2. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    I am confused. you should be forwarding port 80 on the computer serving the PHP file and database. It shouldn't matter what router your client device is connected to.
     
  3. simhamed

    simhamed Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    8
    Joined:
    May 7, 2012

    May 7, 2012
    8
    0
    25
    Student
    France
    Well... Actually, you're right! xD

    When I used my external/internet IP address (like the one found on Adresse Ip - Mon IP - Localiser une adresse IP), it didn't work...
    But then I chose the one from cmd/ipconfig and it's working! My bad!
    Thanks a lot!

    But why on my home's network I have to use my external IP address to make it work, while on the university's network I can just use my local/ipconfig IP address?

    Then here's another question: Is there any (easy?) way I can use my app on every network without having to change the IP address on the Eclipse's code everytime?
    Like using a fix IP/link etc for every network?
     
  4. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    You should be using your public IP (the one from the link you posted) always. If it works from outside the network, then it should also work from inside the network.
     

Share This Page

Loading...