SensorModelDataCollector/src/com/clarkson/sensormodeldatacollector/WiFiScanActivity.java
/** 
	 * Tests the apps ability to connect to the Servlet
	 */
Tests the apps ability to connect to the Servlet
Tests the apps ability to connect to the Servlet
boolean testServerConnection()
	{
		boolean server_status = false;
		Random test_code_generator = new Random();
		int test_code_number = test_code_generator.nextInt(10); 
        int test_code_response = 0;
		try{
            URL url = new URL(mDefaultServerURL);
            URLConnection sensor_model_servlet = url.openConnection();
            String test_code_input_string = String.valueOf(test_code_number);
            Log.d(getLocalClassName(), "Test code input: " + test_code_input_string);
            sensor_model_servlet.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(sensor_model_servlet.getOutputStream());
            out.write(test_code_input_string);
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(sensor_model_servlet.getInputStream()));
            String returnString="";
            mServerConnectionCode = ServerStatus.SENSOR_MODEL_SERVER_DISCONNECTED;
            while ((returnString = in.readLine()) != null) 
            {
            	Log.d("returnString", returnString);
            	Log.d("enum value connected: ", ServerStatus.SENSOR_MODEL_SERVER_CONNECTED.toString());
            	test_code_response = Integer.valueOf(returnString);
            }
            in.close();
            }
			catch(Exception e)
            {
                Log.d("Exception",e.toString());
            }
		if(test_code_response == test_code_number*2 && test_code_response <= 20)
        {
        	server_status = true;  
        	Log.d(getLocalClassName(), "Test code response: " + String.valueOf(test_code_response));
        }  
		return server_status;
	}
boolean testServerConnection ( ) { boolean server_status = false ; Random test_code_generator = new Random ( ) ; int test_code_number = test_code_generator . nextInt ( 10 ) ; int test_code_response = 0 ; try { URL url = new URL ( mDefaultServerURL ) ; URLConnection sensor_model_servlet = url . openConnection ( ) ; String test_code_input_string = String . valueOf ( test_code_number ) ; Log . d ( getLocalClassName ( ) , "Test code input: " + test_code_input_string ) ; sensor_model_servlet . setDoOutput ( true ) ; OutputStreamWriter out = new OutputStreamWriter ( sensor_model_servlet . getOutputStream ( ) ) ; out . write ( test_code_input_string ) ; out . close ( ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( sensor_model_servlet . getInputStream ( ) ) ) ; String returnString = "" ; mServerConnectionCode = ServerStatus . SENSOR_MODEL_SERVER_DISCONNECTED ; while ( ( returnString = in . readLine ( ) ) != null ) { Log . d ( "returnString" , returnString ) ; Log . d ( "enum value connected: " , ServerStatus . SENSOR_MODEL_SERVER_CONNECTED . toString ( ) ) ; test_code_response = Integer . valueOf ( returnString ) ; } in . close ( ) ; } catch ( Exception e ) { Log . d ( "Exception" , e . toString ( ) ) ; } if ( test_code_response == test_code_number * 2 && test_code_response <= 20 ) { server_status = true ; Log . d ( getLocalClassName ( ) , "Test code response: " + String . valueOf ( test_code_response ) ) ; } return server_status ; }
Tests the apps ability to connect to the Servlet
Tests the apps ability to connect to the Servlet
//Generate random number between 0 and 10
 //108.26.49.81
 //URL url = new URL("http://108.26.49.81:9999/SensorModelServletProject/SensorModelServlet");
 //inputString = URLEncoder.encode(inputString, "UTF-8");
