简体   繁体   English

使用翻新2上传视频时ETIMEDOUT(连接超时)

[英]ETIMEDOUT (Connection timed out) when uploading video using retrofit 2

I am using this code to upload my videos to the retrofit server 我正在使用此代码将我的视频上传到改造服务器

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;
}

It uploaded the video for first times the connection is set, however, it throws out the following error below from time to time. 第一次建立连接时,它会上传视频,但是,有时会抛出以下错误。

libcore.io.ErrnoException: isConnected failed: ETIMEDOUT (Connection timed out) libcore.io.ErrnoException:isConnected失败:ETIMEDOUT(连接超时)

Can anyone explain me why is this happening, and how can I fix it? 谁能解释我为什么会这样,我该如何解决? Right now, I am looking into solutions how I can close my connection since I doubt that it might be because of the unclosed connection. 目前,我正在研究如何关闭连接的解决方案,因为我怀疑这可能是由于未关闭的连接所致。

这是由于未释放连接导致的,我通过放置一个

response.body().close(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android套接字连接拒绝ETIMEDOUT(连接超时) - Android Socket Connection Refused ETIMEDOUT (Connection timed out) 如何修复连接超时 - how to fix connection timed out in retrofit 如何解决无法连接到 /192.168.15.186(端口 80):连接失败:Windows 防火墙中的 ETIMEDOUT(连接超时) - how to resolve failed to connect to /192.168.15.186 (port 80): connect failed: ETIMEDOUT (Connection timed out) in Windows Firewall java.net.ConnectException:无法连接到/10.0.0.2(端口80):连接失败:ETIMEDOUT(连接超时) - java.net.ConnectException: failed to connect to /10.0.0.2 (port 80): connect failed: ETIMEDOUT (Connection timed out) IOException:无法连接到 /192.168.70.1(端口 9900):连接失败:ETIMEDOUT(连接超时) - IOException: failed to connect to /192.168.70.1 (port 9900): connect failed: ETIMEDOUT (Connection timed out) 如何解决java.net.ConnectException:无法连接到/10.0.2.2(端口8080):连接失败:ETIMEDOUT(连接超时) - how to resolve java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: ETIMEDOUT (Connection timed out) heroku 连接超时(连接超时) - heroku Connection timed out (Connection timed out) 连接超时页面 - Connection Timed out Page 网址连接超时 - Url Connection timed out JavaSocket连接超时 - JavaSocket connection timed out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM