Я использую этот код, чтобы загрузить свои видео на сервер дооснащенияETIMEDOUT (подключение истекло) при загрузке видео с помощью переоснащения 2
private String uploadVideoToServer(String pathToVideoFile) {
Log.v("test_get", "get the file");
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://xxx.xxx.xxx.xxx:xxxx/")
.addConverterFactory(GsonConverterFactory.create())
.build();
SmileVideoAPI service = retrofit.create(SmileVideoAPI.class);
MediaType MEDIA_TYPE = MediaType.parse("multipart/form-data");
File videoFile = new File(pathToVideoFile);
//RequestBody videoBody = RequestBody.create(MEDIA_TYPE, videoFile);
ProgressRequestBody videoBody = new ProgressRequestBody(videoFile, this);
MultipartBody.Part vFile = MultipartBody.Part.createFormData("file", videoFile.getName(), videoBody);
RequestBody description = createPartFromString("desc");
Log.v("test_get", "before uploading");
Call<ResponseBody> call = service.uploadVideo(description, vFile);
Log.v("test_get", "after uploading");
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
Log.i("mok", "S");
ResponseBody rb = response.body();
Log.i("mok", rb.toString());
mProgress.setProgress(100);
Intent intent = new Intent(UploadActivity.this, UploadCompleteActivity.class);
startActivity(intent);
finish();
} else {
Log.i("mok", "F");
ResponseBody rb = response.errorBody();
Log.i("mok", rb.toString());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
t.printStackTrace();
Log.i("mok", t.getCause() + "");
Log.i("mok", "T");
Toast.makeText(getApplicationContext(), "Upload fail", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(UploadActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});
return msg;
}
Он загрузил видео на первый раз соединение устанавливается, однако, его время от времени выдает следующую ошибку ниже.
libcore.io.ErrnoException: IsConnected не удалось: ETIMEDOUT (подключение истекло)
Может кто-нибудь объяснить мне, почему это происходит, и как я могу это исправить? Прямо сейчас, я рассматриваю решения, как я могу закрыть свое соединение, так как я сомневаюсь, что это может быть из-за незакрытого соединения.