title: Set Socket time out in SSL Connection
body: <p>Hi would like to know if there is a way to set a timeout to a socket and the numbers of retries that it does until the connection gets a handshake. I tested my app in very bad connection mode and i set a retry policy for my request in Volley to 10 sec but the SSL handshake seems to be the problem because it´s having a default timeout set by 60 sec and the Volley timeout only gets fired when the sockets fails becuase of the number of attempts or by the timeout .</p>
  
  <p>Here is my method:</p>
  
  <pre><code>private SSLSocketFactory newSslSocketFactory() {
          try {
              // Get an instance of the Bouncy Castle KeyStore format
              KeyStore trusted = KeyStore.getInstance("BKS");
              // Get the raw resource, which contains the keystore with
              // your trusted certificates (root and any intermediate certs)
              InputStream in = getApplicationContext().getResources().openRawResource(R.raw.muip);
              try {
                  // Initialize the keystore with the provided trusted certificates
                  // Provide the password of the keystore
                  trusted.load(in, KEYSTORE_PASSWORD.toCharArray());
              } finally {
                  in.close();
              }
  
              String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
              TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
              tmf.init(trusted);
  
  
  
              SSLContext context = SSLContext.getInstance("TLS");
              context.init(null, tmf.getTrustManagers(), null);
  
              SSLSocketFactory sf = new NoSSLv3Factory(context.getSocketFactory());
              HttpsURLConnection.setDefaultSSLSocketFactory(sf);
  
  
  
  
  
              return sf;
          } catch (Throwable e) {
              Log.e(TAG, "newSslSocketFactory: "+ e.getMessage(),e );
              throw new AssertionError(e);
          }
      }
  </code></pre>
  
  <p>I am using Volley to make my requests and the method where i implementing this is in:</p>
  
  <pre><code> public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              Network network = new BasicNetwork(new HurlStack(null, newSslSocketFactory()));
  
              Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
              mRequestQueue = new RequestQueue(cache, network);
              mRequestQueue.start();
          }
  
          return mRequestQueue;
      }
  </code></pre>
  
  <p>I also tried to set the timeout like this:</p>
  
  <pre><code>    SSLSocketFactory sf = new NoSSLv3Factory(SSLCertificateSocketFactory.getDefault(10000, new SSLSessionCache(this)));
  </code></pre>