@ Override public Socket createSocket ( final String host , final int port , final InetAddress localAddress , final int localPort , final HttpConnectionParams params ) throws IOException , UnknownHostException , ConnectTimeoutException { if ( params == null ) { throw new IllegalArgumentException ( "Parameters may not be null" ) ; } int timeout = params . getConnectionTimeout ( ) ; if ( timeout == 0 ) { InetAddress hostAddress = getCachedMisconfiguredHost ( host , port ) ; if ( hostAddress != null ) { return clientSSLSockFactory . createSocket ( hostAddress , port , localAddress , localPort ) ; } try { SSLSocket sslSocket = ( SSLSocket ) clientSSLSockFactory . createSocket ( host , port , localAddress , localPort ) ; sslSocket . startHandshake ( ) ; return sslSocket ; } catch ( SSLException e ) { if ( ! e . getMessage ( ) . contains ( CONTENTS_UNRECOGNIZED_NAME_EXCEPTION ) ) { throw e ; } hostAddress = InetAddress . getByName ( host ) ; cacheMisconfiguredHost ( host , port , hostAddress ) ; return clientSSLSockFactory . createSocket ( hostAddress , port , localAddress , localPort ) ; } } Socket socket = clientSSLSockFactory . createSocket ( ) ; SocketAddress localAddr = new InetSocketAddress ( localAddress , localPort ) ; socket . bind ( localAddr ) ; SocketAddress remoteAddr = new InetSocketAddress ( host , port ) ; socket . connect ( remoteAddr , timeout ) ; return socket ; }
Attempts to get a new socket connection to the given host within the given time limit .