Android 文件结束异常

Android 文件结束异常,android,mysql,node.js,runnable,eofexception,Android,Mysql,Node.js,Runnable,Eofexception,你好 我的NodeJS服务器有问题 我有一个android应用程序,每30秒通过HttpUrlConnection从MySQL数据库获取信息。应用程序和我的服务器工作正常。但是大约(不确定)10分钟或20分钟后?我的服务器什么也不做,在我的日志中,它说我的应用程序抛出了EOFEException 有人能帮我修一下吗 此图像显示应用程序工作正常 和我的服务器 但过了一段时间 服务器变成了这个 这是我从mysql节点服务器获取信息的代码 protected String doInBa

你好

我的NodeJS服务器有问题

我有一个android应用程序,每30秒通过HttpUrlConnection从MySQL数据库获取信息。应用程序和我的服务器工作正常。但是大约(不确定)10分钟或20分钟后?我的服务器什么也不做,在我的日志中,它说我的应用程序抛出了EOFEException

有人能帮我修一下吗

此图像显示应用程序工作正常

和我的服务器

但过了一段时间

服务器变成了这个

这是我从mysql节点服务器获取信息的代码

    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;
}
用于从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);