package com.utbm.lo53.whereami;

import android.util.Log;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public final class Connection
{
    public static String command(String ip,String port,String cmd)
    {
        String data="";
        try
        {

            URL url=new URL("http://"+ip+":"+port+"/Where-I-Am/index.php"+cmd);
            HttpURLConnection httpconn=(HttpURLConnection)url.openConnection();
            httpconn.setRequestMethod("GET");
            httpconn.connect();
            int response=httpconn.getResponseCode();
            if( response == HttpURLConnection.HTTP_OK ) {
                InputStream in = httpconn.getInputStream();
                InputStreamReader isr = new InputStreamReader(in);
                BufferedReader br = new BufferedReader(isr);
                data = br.readLine();
            }
            Log.d("address","http://"+ip+":"+port+"/Where-I-Am/index.php"+cmd);
        } catch (Exception em){
            Log.d("Error","Error");
        }
        return data;
    }

}
