public void connect(SocketAddress endpoint,int timeout) throws IOException {
  if (endpoint == null)   throw new IllegalArgumentException("connect: The address can't be null");
  if (timeout < 0)   throw new IllegalArgumentException("connect: timeout can't be negative");
  if (isClosed())   throw new SocketException("Socket is closed");
  if (!oldImpl && isConnected())   throw new SocketException("already connected");
  if (!(endpoint instanceof InetSocketAddress))   throw new IllegalArgumentException("Unsupported address type");
  InetSocketAddress epoint=(InetSocketAddress)endpoint;
  InetAddress addr=epoint.getAddress();
  int port=epoint.getPort();
  checkAddress(addr,"connect");
  SecurityManager security=System.getSecurityManager();
  if (security != null) {
    if (epoint.isUnresolved())     security.checkConnect(epoint.getHostName(),port);
 else     security.checkConnect(addr.getHostAddress(),port);
  }
  if (!created)   createImpl(true);
  if (!oldImpl)   impl.connect(epoint,timeout);
 else   if (timeout == 0) {
    if (epoint.isUnresolved())     impl.connect(addr.getHostName(),port);
 else     impl.connect(addr,port);
  }
 else   throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)");
  connected=true;
  bound=true;
}

public void connect ( SocketAddress endpoint , int timeout ) throws IOException { if ( endpoint == null ) throw new IllegalArgumentException ( "connect: The address can't be null" ) ; if ( timeout < 0 ) throw new IllegalArgumentException ( "connect: timeout can't be negative" ) ; if ( isClosed ( ) ) throw new SocketException ( "Socket is closed" ) ; if ( ! oldImpl && isConnected ( ) ) throw new SocketException ( "already connected" ) ; if ( ! ( endpoint instanceof InetSocketAddress ) ) throw new IllegalArgumentException ( "Unsupported address type" ) ; InetSocketAddress epoint = ( InetSocketAddress ) endpoint ; InetAddress addr = epoint . getAddress ( ) ; int port = epoint . getPort ( ) ; checkAddress ( addr , "connect" ) ; SecurityManager security = System . getSecurityManager ( ) ; if ( security != null ) { if ( epoint . isUnresolved ( ) ) security . checkConnect ( epoint . getHostName ( ) , port ) ; else security . checkConnect ( addr . getHostAddress ( ) , port ) ; } if ( ! created ) createImpl ( true ) ; if ( ! oldImpl ) impl . connect ( epoint , timeout ) ; else if ( timeout == 0 ) { if ( epoint . isUnresolved ( ) ) impl . connect ( addr . getHostName ( ) , port ) ; else impl . connect ( addr , port ) ; } else throw new UnsupportedOperationException ( "SocketImpl.connect(addr, timeout)" ) ; connected = true ; bound = true ; }
connects this socket to the server with a specified timeout value . a timeout of zero is interpreted as an infinite timeout . the connection will then block until established or an error occurs .
