파일 업로드 앱을 쓰고 있습니다. asyn 메서드를 사용하여 서버에 연결하고 파일 (apache http)을 업로드 할 수 있습니다.
서버에서 연결 수의 한계를 100으로 설정했습니다. 연결이 마지막 인 경우 연결을 끊기 위해 연결 시간 초과를 설정하고 싶습니다.
다음은 흐름입니다.
(1) Android 클라이언트가 서버에 연결을 설정합니다. 아직 살아 60 년대 이후에 연결이 다음 안드로이드 클라이언트설정된 http 연결을 끊기 위해 시간 초과를 설정할 수 있습니까?
에서 분리하면
는 (2) 나는이 작동하지 않습니다 HttpParams에 해당 세트 제한 시간을 알고 (시작은 60 년대에 대한 계산). 어떻게해야할지 모르겠다.
누구나 어떻게 할 수 있습니까? 어떤 해결책이나 제안을 환영합니다. 감사!
client.getConnectionManager().shutdown();
을하지만에 60 년대에 대한 방법을 셀 수 : 호출하여
try
{
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 60000);
HttpConnectionParams.setSoTimeout(httpParameters, 60000);
HttpClient client = new DefaultHttpClient(httpParameters);
...
ByteArrayBody bab = new ByteArrayBody(byteArray, "photo.jpg");
entity.addPart("photo", bab);
httpPost.setEntity(entity);
startTime = System.currentTimeMillis();
//ClientConnectionRequest connRequest = new ManagedClientConnection();
//httpPost.setConnectionRequest((ClientConnectionRequest) connRequest.getConnection(3000, TimeUnit.MILLISECONDS));
HttpResponse response = client.execute(httpPost, localContext);
Handler mHandler = new Handler();
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String result = "";
String tmp = "";
while ((tmp = reader.readLine()) != null)
{
result += tmp;
}
reader.close();
return result;
} catch (Exception e) {
Log.e(TAG, "error time = " + (System.currentTimeMillis() - startTime));
Log.e("httpUploadHandler", "Some error came up");
Log.e("httpUploadHandler", e.toString());
}
내가 연결을 해제 할 수 있습니다 : 여기
내 보내기 파일 메서드는 AsyncTask을 확장하는 클래스 내에 있습니다. 'Looper.prepare()'를 호출하지 않은 스레드 내부에서 핸들러를 생성 할 수 없다는 오류가 발생합니다. 당신이 제안한대로 할 수있는 일이 있습니까? Thanks –
이 코드를 AsyncTask의 onPreExecute()에 넣으십시오. – Akhil
감사합니다. 작동합니다. 나는 'httpAsync.mRedrawHandler.doJob (60000);'을 넣었다. 전에 "HttpResponse response = client.execute (httpPost, localContext);". 하지만 내가 원하는 것은 100 %가 아닙니다. 실제로 연결이 성공적으로 이루어진 후 'doJob (60000)'을 시작하고 싶습니다. 그것을 감지 할 수 있습니까? –