Good day.
I have a problem with my NodeJS server.
I have an android app that gets information from MySQL database thru HttpUrlConnection every 30 seconds. The app and my server are working fine. But after about (not sure) 10 minutes or 20? my server does nothing and in my Logcat it says that my app throws EOFException
can someone help me fix this?
this image shows the app is working fine
and my server
but after sometime
server became this
this is my codes in getting info from mysql nodejs server
protected String doInBackground(String... arg0) {
HttpURLConnection connection = null;
HttpURLConnection connection1 = null;
String json = (String) arg0[0];
System.setProperty("http.keepAlive", "false");
try {
URL u = new URL("http://"+ MainActivity.ipadd +"/getmessage");
connection = (HttpURLConnection) u.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "close");
connection.setRequestProperty("Content-Type","application/json");
//connection.setConnectTimeout(10000);
//connection.setReadTimeout(15000);
if (json != null) {
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
Log.i("message", "To send : " + json);
byte[] outputInBytes = json.getBytes("UTF-8");
OutputStream os = connection.getOutputStream();
os.write( outputInBytes );
os.close();
os.flush();
}
//Connect to the server
connection.connect();
int status = connection.getResponseCode();
String staRes = connection.getResponseMessage().toString();
Log.i("HTTP Client", "HTTP status code : " + status + " " + staRes);
switch (status) {
case 200:
case 201:
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line + "\n");
}
bufferedReader.close();
Log.i("HTTP Client", "Response : " + sb.toString());
//return received string
holds.setRespone(sb.toString());
jo = new JSONObject(sb.toString());
jof = new JSONObject();
String tmp = jo.optString("mess");
String tmpp = jo.optString("cp");
String reff = jo.optString("ref");
boolean tmppp = false;
//jof.put("ref", jo.opt("ref"));
if(tmp.contains("err_code_01")){
tmppp = sendSMSMessage(tmpp, "Your MESSAGE was rejected. It contains wrong format.\nTrace Number:" + reff + "\nDo not reply.");
Log.v("sent message", "Your MESSAGE was rejected. It contains wrong format.");
} else if(tmp.contains("err_code_03")){
tmppp = sendSMSMessage(tmpp, "Your MESSAGE was rejected. It contains wrong position format.\nTrace Number:" + reff + "\nDo not reply.");
Log.v("sent message", "Your MESSAGE was rejected. It contains wrong position format.");
} else if(tmp.contains("err_code_04")){
tmppp = sendSMSMessage(tmpp, "Your MESSAGE was rejected. It contains wrong candidate-position format.\nTrace Number:" + reff + "\nDo not reply.");
Log.v("sent message", "Your MESSAGE was rejected. It contains wrong candidate-position format.");
} else if(tmp.contains("err_code_05")){
tmppp = sendSMSMessage(tmpp, "Your MESSAGE was rejected. It contains wrong vote count format.\nTrace Number:" + reff + "\nDo not reply.");
Log.v("sent message", "Your MESSAGE was rejected. It contains wrong vote count format.");
} else if(tmp.contains("success")){
tmppp = sendSMSMessage(tmpp, "Your MESSAGE was accepted.\nTrace Number:" + reff + "\nDo not reply.");
Log.v("sent message", "Your MESSAGE was accepted.");
}
return sb.toString();
}
} catch (MalformedURLException ex) {
Log.e("HTTP Client", "Error in HTTP Connection(Malformed URL) " + ex);
} catch (IOException ex) {
Log.e("HTTP Client", "Error in HTTP Connection(IO Exception) " + ex);
} catch (Exception ex) {
Log.e("HTTP Client", "Error in HTTP Connection(Exception) " + ex);
} finally {
//if (connection != null) {
//try {
connection.disconnect();
//} catch (Exception ex) {
// Log.e("HTTP Client", "Error in HTTP Connection " + ex.toString());
//}
//}
}
return null;
}
and for calling from MainActivity.class
final Handler handlerr = new Handler();
runnableGet = new Runnable(){
@Override
public void run() {
try{
gett = new GetMessageFromServer();
gett.execute(tmpp.toString());
}catch (Exception e){
//err here
Log.v("err", "runnable: " + e.toString());
} finally{
handlerr.postDelayed(runnableGet, 30000);
}
}
};
handlerr.postDelayed(runnableGet, 30000);