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) {
            return createSocket(host, port);
        } else {
            // To be eventually deprecated when migrated to Java 1.4 or above
            Socket socket = ReflectionSocketFactory.createSocket(
                "javax.net.ssl.SSLSocketFactory", host, port, null, 0, timeout);
            if (socket == null) {
                socket = ControllerThreadSocketFactory.createSocket(
                    this, host, port, null, 0, timeout);
            }
            return socket;
        }
    }
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 ) { return createSocket ( host , port ) ; } else { Socket socket = ReflectionSocketFactory . createSocket ( "javax.net.ssl.SSLSocketFactory" , host , port , null , 0 , timeout ) ; if ( socket == null ) { socket = ControllerThreadSocketFactory . createSocket ( this , host , port , null , 0 , timeout ) ; } return socket ; } }
Attempts to get a new socket connection to the given host within the given time limit.
<p>
This method employs several techniques to circumvent the limitations of older JREs that
do not support connect timeout. When running in JRE 1.4 or above reflection is used to
call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older
JREs a controller thread is executed. The controller thread attempts to create a new socket
within the given limit of time. If socket constructor does not return until the timeout
expires, the controller terminates and throws an {@link ConnectTimeoutException}
</p>

@param host the host name/IP
@param port the port on the host
@param localAddress the local host name/IP to bind the socket to, ignored.
@param localPort the port on the local machine, ignored.
@param params {@link HttpConnectionParams Http connection parameters}

@return Socket a new socket

@throws IOException if an I/O error occurs while creating the socket
@throws UnknownHostException if the IP address of the host cannot be
determined

@since 3.0