2017-03-12 2 views
-1

Pycharm (플라스크와 파이썬) 서버와 함께 Android asyntask를 사용 중이며 배열을 반환합니다. 서버와 연결을 시도했을 때 연결이 거부되었다고 표시됩니다. 연결 거부와 같은 오류가 나타나는 이유가 해결책이 필요합니다.원인 : android.system.ErrnoException : isConnected failed : ECONNREFUSED (연결이 거부 됨)

안드로이드 코드 :

public static String ip = "http://192.168.43.221:3000/"; 
    private class BackTask extends AsyncTask<String, String, String> { 

      private String result = null,name,batch,id,dept,dob,phno,add,credits; 

      @Override 
      protected String doInBackground(String... params) { 
       try { 
        String data = URLEncoder.encode("device", "UTF-8") + "=" + 
          URLEncoder.encode(device, "UTF-8") + "&" + 
          URLEncoder.encode("ID", "UTF-8") + "=" + 
          URLEncoder.encode(regno1, "UTF-8") + "&" + 
          URLEncoder.encode("Password", "UTF-8") + "=" + 
          URLEncoder.encode(password1, "UTF-8"); 

        BufferedReader reader = null; 
        Log.d("checking", data); 
        try { 
         URL url = new URL(ip + "login/"); 
         URLConnection con = url.openConnection(); 
         con.setDoOutput(true); 
         OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream()); 
         writer.write(data); 
         writer.flush(); 
         //getting response back 
         reader = new BufferedReader(new InputStreamReader(con.getInputStream())); 
         Toast.makeText(getBaseContext(),reader.readLine(),Toast.LENGTH_LONG).show(); 
         StringBuilder s = new StringBuilder(); 
         String line = null; 
         while ((line = reader.readLine()) != null) { 
          s.append(line + "\n"); 
         } 
         result = s.toString(); 
        } catch (Exception e) { 
    //     Toast.makeText(getBaseContext(),"Connection error",Toast.LENGTH_LONG).show(); 
         e.printStackTrace(); 
        } 
       } catch (UnsupportedEncodingException e) { 
        Toast.makeText(getBaseContext(),"Connection error",Toast.LENGTH_LONG).show(); 
        e.printStackTrace(); 
       } 
       return result; 

      } 

      @Override 
      protected void onPostExecute(String result) { 
       Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show(); 
       SharedPreferences.Editor e = sp1.edit(); 
       if(!sp1.equals(null)) 
       { 

        e.putString("uname", regno1); 
        e.putString("pass", password1); 
        e.apply(); 
       } 
       // progress.dismiss(); 
       //notification.setText(result); 
       if (result != null) { 
        Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show(); 
        result = result.trim(); 
        name= setDetails(result); 


        if (name.equals("success")) { 
         Intent intent1 = new Intent(LoginActivity.this, HrActivity.class); 
         //intent.putExtra("json",result); 
         startActivity(intent); 
        } else { 
         errormsg.setText("*Check id/password"); 
        } 
       } 
      } 

      @Override 
      protected void onPreExecute() { 
       progress.show(); 
      } 

      @Override 
      protected void onProgressUpdate(String... text) { 
       // progress. For example updating ProgessDialog 
      } 

로그 캣 :

03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at libcore.io.IoBridge.isConnected(IoBridge.java:267) 
03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at libcore.io.IoBridge.connectErrno(IoBridge.java:191) 
03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at libcore.io.IoBridge.connect(IoBridge.java:127) 
03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:188) 
03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:461) 
03-12 13:52:48.194 23394-23527/com.example.dinesh.eis W/System.err:  at java.net.Socket.connect(Socket.java:918) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.Connection.connect(Connection.java:152) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:282) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:216) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:391) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.example.dinesh.eis.LoginActivity$BackTask.doInBackground(LoginActivity.java:121) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at com.example.dinesh.eis.LoginActivity$BackTask.doInBackground(LoginActivity.java:101) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at android.os.AsyncTask$2.call(AsyncTask.java:292) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
03-12 13:52:48.195 23394-23527/com.example.dinesh.eis W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
03-12 13:52:48.197 23394-23527/com.example.dinesh.eis W/System.err:  at java.lang.Thread.run(Thread.java:818) 
03-12 13:52:48.197 23394-23527/com.example.dinesh.eis W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused) 
03-12 13:52:48.198 23394-23527/com.example.dinesh.eis W/System.err:  at libcore.io.IoBridge.isConnected(IoBridge.java:252) 
03-12 13:52:48.198 23394-23527/com.example.dinesh.eis W/System.err:  ... 20 more 

답변

0

ECONNREFUSED가 연결이 원격 서버에 시도 의미하는 것입니다, 그러나 원격 호스트가 다시 응답하지 않습니다. 이것은 누군가의 문을 두드리는 것과 매우 흡사하며 아무도 답장을 보내지 않습니다. 당신의 무서워에 대한 직접적인 대답은 없습니다. thisthis 스레드를 살펴보십시오. 핵심 문제에 대한 통찰력을 제공 할 수 있으며 코드 분석 및 디버깅을 시작할 수 있습니다.

관련 문제