retrofit: retrofit.RetrofitError: sendto failed: ECONNRESET (Connection reset by peer)
I am uploading images with retrofit multipart and continuously getting the following exception :
Caused by: retrofit.RetrofitError: sendto failed: ECONNRESET (Connection reset by peer) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395) at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240) at java.lang.reflect.Proxy.invoke(Proxy.java:397) at $Proxy2.uploadImage(Unknown Source) at gaadi.evaluator.com.retrofit.RetrofitRequest.makeImageUploadRequest(RetrofitRequest.java:26) at gaadi.evaluator.com.service.ImageUploadServiceRevamp.onHandleIntent(ImageUploadServiceRevamp.java:73) … 4 more Caused by: java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer) at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546) at libcore.io.IoBridge.sendto(IoBridge.java:515) at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504) at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37) at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266) at okio.Okio$1.write(Okio.java:78) at okio.AsyncTimeout$1.write(AsyncTimeout.java:155) at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) at okio.RealBufferedSink.write(RealBufferedSink.java:46) at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302) at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) at okio.RealBufferedSink$1.write(RealBufferedSink.java:198) at retrofit.mime.TypedFile.writeTo(TypedFile.java:78) at retrofit.mime.MultipartTypedOutput$MimePart.writeTo(MultipartTypedOutput.java:54) at retrofit.mime.MultipartTypedOutput.writeTo(MultipartTypedOutput.java:144) at retrofit.client.OkClient$1.writeTo(OkClient.java:88) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:898) at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760) at com.squareup.okhttp.Call.getResponse(Call.java:274) at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230) at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201) at com.squareup.okhttp.Call.execute(Call.java:81) at retrofit.client.OkClient.execute(OkClient.java:53) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326) … 9 more Caused by: android.system.ErrnoException: sendto failed: ECONNRESET (Connection reset by peer) at libcore.io.Posix.sendtoBytes(Native Method) at libcore.io.Posix.sendto(Posix.java:176) at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278) at libcore.io.IoBridge.sendto(IoBridge.java:513) … 31 more
The adapter i am using is :
public static RestAdapter getRestAdapter(Context context){ String url = Utils.getWebServiceURL(context); String urlBase = url.substring(0, url.lastIndexOf(“/”));
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
okHttpClient.setWriteTimeout(60, TimeUnit.SECONDS);
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectionPool(new ConnectionPool(0, 5 * 60 * 1000));
return new RestAdapter.Builder()
.setEndpoint(urlBase)
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setClient(new OkClient(okHttpClient))
.build();
}
Interface method used for making request is as follows : @Multipart @POST(“/{path}”) public ImageUploadResponse uploadImage(@Path(“path”) String path, @Part(Constants.EVALUATION_DATA) String map, @Part(“certImg”) TypedFile file);
Call made to this interface method is as follows : TypedFile file = new TypedFile(“multipart/form-data”, new File(imagePath)); String url = Utils.getWebServiceURL(UILApplication.getInstance()); return requestInterface.uploadDocumentImage(path, jsonParams, file);
Could not find a solution to this on stackoverflow.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 16 (1 by maintainers)
The server you are connecting to has closed the connection for whatever reason. You need to speak to the people who run the server and see what’s happening. Could be an invalid request, broken server, invalid format, etc. This isn’t a problem with Retrofit itself.
It may be caused by the long connection maintenance time of the client is longer than that of the server. Two solutions:
or