Tabnine Logo
OkHttpClient.setConnectTimeout
Code IndexAdd Tabnine to your IDE (free)

How to use
setConnectTimeout
method
in
okhttp3.OkHttpClient

Best Java code snippets using okhttp3.OkHttpClient.setConnectTimeout (Showing top 20 results out of 315)

origin: stackoverflow.com

 OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(15, TimeUnit.SECONDS);    // socket timeout

Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
origin: stackoverflow.com

 public RestAdapter providesRestAdapter(Gson gson) {
  final OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
  okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);

  return new RestAdapter.Builder()
    .setEndpoint(BuildConfig.BASE_URL)
    .setConverter(new GsonConverter(gson))
    .setClient(new OkClient(okHttpClient))
    .build();
}
origin: stackoverflow.com

 private OkHttpClient getClient() {
  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(5, TimeUnit.MINUTES);
  client.setReadTimeout(5, TimeUnit.MINUTES);
  return client;
}
origin: stackoverflow.com

 OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(30, TimeUnit.SECONDS);    // socket timeout
origin: stackoverflow.com

 OkHttpClient defaultClient() {   
  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(15, TimeUnit.SECONDS);
  client.setReadTimeout(15, TimeUnit.SECONDS);
  client.setWriteTimeout(15, TimeUnit.SECONDS);
  return client;
}
origin: stackoverflow.com

 public WebServiceClient() {
  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(10, TimeUnit.SECONDS);
  client.setReadTimeout(30, TimeUnit.SECONDS);
  client.interceptors().add(new Interceptor() {
    @Override
    public Response intercept(Chain chain) throws IOException {
      return onOnIntercept(chain);
    }
  });
  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(BASE_URL)
      .addConverterFactory(GsonConverterFactory.create())
      .client(client)
      .build();
  webService = retrofit.create(WebService.class);
}
origin: stackoverflow.com

private OkHttpClient getRequestHeader() {
   OkHttpClient httpClient = new OkHttpClient();
   httpClient.setConnectTimeout(20, TimeUnit.SECONDS);
   httpClient.setReadTimeout(30, TimeUnit.SECONDS);
   return httpClient;
 }
origin: stackoverflow.com

 OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(10, TimeUnit.SECONDS);
client.setReadTimeout(30, TimeUnit.SECONDS);
retrofit = new Retrofit.Builder()
    .baseUrl(BASE_URL)
    .addConverterFactory(GsonConverterFactory.create())
    .client(client)
    .build();
origin: stackoverflow.com

Picasso picasso;
 OkHttpClient okHttpClient;
 okHttpClient = new OkHttpClient();
 okHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
 picasso = new Picasso.Builder(this)
     .downloader(new OkHttpDownloader(okHttpClient))
     .build();
origin: stackoverflow.com

 public static InputStream downloadFileThrowing(String url, int timeOutInSeconds) throws IOException {

  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(timeOutInSeconds, TimeUnit.SECONDS);
  client.setReadTimeout(timeOutInSeconds, TimeUnit.SECONDS);

  Request request = new Request.Builder().url(url).build();

  Response response = client.newCall(request).execute();
  if (!response.isSuccessful())
    throw new IOException("Download not successful.response:" + response);
  else
    return response.body().byteStream();
}
origin: stackoverflow.com

 public static InputStream downloadFileThrowing(String url, int timeOutInSeconds) throws IOException {

  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(timeOutInSeconds, TimeUnit.SECONDS);
  client.setReadTimeout(timeOutInSeconds, TimeUnit.SECONDS);

  Request request = new Request.Builder().url(url).build();

  Response response = client.newCall(request).execute();
  if (!response.isSuccessful())
    throw new IOException("Download not successful.response:" + response);
  else
    return response.body().byteStream();
}
origin: stackoverflow.com

 final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
origin: stackoverflow.com

 OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(20, TimeUnit.SECONDS);  // connect timeout
client.setReadTimeout(20, TimeUnit.SECONDS);     // socket timeout
origin: stackoverflow.com

OkHttpClient client = new OkHttpClient();
   client.setConnectTimeout(connectTimeOut, TimeUnit.SECONDS);
   client.setReadTimeout(readTime, TimeUnit.SECONDS);
   File cachePath = FuncFileDownload.getStoragePath(context, "pre");
   client.setCache(new com.squareup.okhttp.Cache(cachePath, 30000000));
   sPicasso = new Picasso.Builder(context)
       .downloader(new OkHttpDownloader(client))
       .build();
   Picasso.setSingletonInstance(sPicasso);
origin: stackoverflow.com

OkHttpClient client = new OkHttpClient();
 client.setConnectTimeout(30, TimeUnit.SECONDS);
 client.setReadTimeout(30, TimeUnit.SECONDS);
 client.setWriteTimeout(30, TimeUnit.SECONDS);
 Retrofit retrofit = new Retrofit.Builder()
     .baseUrl("http://api.yourapp.com/")
     .addConverterFactory(GsonConverterFactory.create())
     .client(client)
     .build();
origin: stackoverflow.com

 public class ServiceGeneratorFileUpload {

public static final String API_BASE_URL = Constant.BASE_URL;

private static OkHttpClient getClient() {
  OkHttpClient client = new OkHttpClient();
  client.setConnectTimeout(4, TimeUnit.MINUTES);
  client.setReadTimeout(4, TimeUnit.MINUTES);
  return client;
}

private final static OkHttpClient httpClient = getClient();

private static Retrofit.Builder builder =
    new Retrofit.Builder()
        .baseUrl(API_BASE_URL)
        .addConverterFactory(GsonConverterFactory.create());

public static <S> S createService(Class<S> serviceClass) {
  Retrofit retrofit = builder.client(httpClient).build();
  return retrofit.create(serviceClass);
  }
}
origin: stackoverflow.com

 public static OkClient createClient(int readTimeout, TimeUnit readTimeoutUnit, int connectTimeout, TimeUnit connectTimeoutUnit)
{
  final OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setReadTimeout(readTimeout, readTimeoutUnit);
  okHttpClient.setConnectTimeout(connectTimeout, connectTimeoutUnit);

  try {
    URL url = new URL(ApiIntentService.getHostAddress());
    SSLSocketFactory NoSSLv3Factory = new NoSSLv3SocketFactory(url);
    okHttpClient.setSslSocketFactory(NoSSLv3Factory);
  } catch (MalformedURLException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }

  return new OkClient(okHttpClient);

}
origin: stackoverflow.com

 public class ServicioConexionRetrofitXML {

  public static final String API_BASE_URL = new GestorPreferencias().getPreferencias().getHost();
  public static final long tiempoMaximoRespuestaSegundos = 60;
  public static final long tiempoMaximoLecturaSegundos = 100;
  public static final OkHttpClient clienteOkHttp = new OkHttpClient();


  private static RestAdapter.Builder builder = new RestAdapter.Builder().
      setEndpoint(API_BASE_URL).
      setClient(new OkClient(clienteOkHttp)).setConverter(new SimpleXMLConverter());


  public static <S> S createService(Class<S> serviceClass) {
    clienteOkHttp.setConnectTimeout(tiempoMaximoRespuestaSegundos, TimeUnit.SECONDS);
    clienteOkHttp.setReadTimeout(tiempoMaximoLecturaSegundos, TimeUnit.SECONDS);
    RestAdapter adapter = builder.build();
    return adapter.create(serviceClass);
  }

}
origin: stackoverflow.com

public class NetworkUtil {
   public static Retrofit getRetrofit() {
     OkHttpClient okHttpClient = new OkHttpClient();
     okHttpClient.setConnectTimeout(AppConstants.TIMEOUT_CONNECT, TimeUnit.SECONDS);
     okHttpClient.setReadTimeout(AppConstants.READ_TIMEOUT, TimeUnit.SECONDS);
     okHttpClient.setWriteTimeout(AppConstants.READ_TIMEOUT, TimeUnit.SECONDS);
     Retrofit retrofit = new Retrofit.Builder()
       .baseUrl(WebServiceConstant.WEBSERVICE_URL_PREFIX)
       .addConverterFactory(GsonConverterFactory.create())
       .build();
     return retrofit;
   }
   public static EndPointInterface endPointInterface(){
     EndPointInterface endPointInterface = new NetworkUtil().getRetrofit().create(EndPointInterface.class);
     return endPointInterface;
   }
 }
origin: stackoverflow.com

 public class NewsController {
  private RestAdapter restAdapter;
  static final String API_URL = "[Enter your API base url here]";
  public void getNews(){
    OkHttpClient mOkHttpClient = new OkHttpClient();
    mOkHttpClient.setConnectTimeout(15000,TimeUnit.MILLISECONDS);
    mOkHttpClient.setReadTimeout(15000,TimeUnit.MILLISECONDS);
    restAdapter = new RestAdapter.Builder().setEndpoint(API_URL).setClient(new OkClient(mOkHttpClient)).setLogLevel(RestAdapter.LogLevel.FULL) .build();
    GetNewsService service = restAdapter.create(GetNewsService.class);

    Callback<List<RootObject> cb = new Callback<List<RootObject>>() {
     @Override 
     public void success(List<RootObject> rootObjectList, Response response) { 
       //whatever you want to do with the fetched news items
     } 

     @Override 
     public void failure(RetrofitError error) { 
      //whatever you want to do with the error
     } 
    };
    service.GetNewsItems(cb);    
  }
}
okhttp3OkHttpClientsetConnectTimeout

Javadoc

Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer#MAX_VALUE when converted to milliseconds.

Popular methods of OkHttpClient

  • newCall
    Prepares the request to be executed at some point in the future.
  • <init>
  • newBuilder
  • dispatcher
  • connectionPool
  • newWebSocket
    Uses request to connect a new web socket.
  • cache
  • connectTimeoutMillis
    Default connect timeout (in milliseconds).
  • interceptors
    Returns an immutable list of interceptors that observe the full span of each call: from before the c
  • readTimeoutMillis
    Default read timeout (in milliseconds).
  • proxy
  • networkInterceptors
    Returns an immutable list of interceptors that observe a single network request and response. These
  • proxy,
  • networkInterceptors,
  • cookieJar,
  • sslSocketFactory,
  • writeTimeoutMillis,
  • followRedirects,
  • hostnameVerifier,
  • retryOnConnectionFailure,
  • authenticator,
  • connectionSpecs

Popular in Java

  • Making http post requests using okhttp
  • getApplicationContext (Context)
  • findViewById (Activity)
  • getSystemService (Context)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Join (org.hibernate.mapping)
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now