コード例 #1
0
  public Socket connectSocket(
      Socket sock,
      String host,
      int port,
      InetAddress localAddress,
      int localPort,
      HttpParams params)
      throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
      if (localPort < 0) {
        localPort = 0;
      }
      InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
      sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
  }
コード例 #2
0
  public Socket connectSocket(
      Socket sock,
      String host,
      int port,
      InetAddress localAddress,
      int localPort,
      HttpParams params)
      throws IOException {
    final int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    final int soTimeout = HttpConnectionParams.getSoTimeout(params);

    final InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    final SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
      // we need to bind explicitly
      if (localPort < 0) {
        localPort = 0; // indicates "any"
      }
      final InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
      sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);

    return sslsock;
  }
コード例 #3
0
  @Override
  public Socket connectSocket(
      Socket sock,
      String host,
      int port,
      InetAddress localAddress,
      int localPort,
      HttpParams params)
      throws IOException, UnknownHostException, ConnectTimeoutException {
    if (host == null) {
      throw new IllegalArgumentException("Target host may not be null.");
    }
    if (params == null) {
      throw new IllegalArgumentException("Parameters may not be null.");
    }

    if (App.DEBUG)
      Log.e(
          TAG + "delete",
          "ConnectSocket with "
              + "\n\t host="
              + host
              + "\n\t port="
              + port
              + "\n\t localport="
              + localPort);

    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
      if (localPort < 0) localPort = 0;

      InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
      sslsock.bind(isa);
    }

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);

    sslsock.connect(remoteAddress, connTimeout);

    sslsock.setSoTimeout(soTimeout);

    try {
      hostnameVerifier.verify(host, sslsock);
    } catch (IOException iox) {
      try {
        sslsock.close();
      } catch (Exception x) {
      }

      throw iox;
    }

    return sslsock;
  }
コード例 #4
0
  // non-javadoc, see interface org.apache.http.conn.SocketFactory
  public Socket connectSocket(
      final Socket sock,
      final String host,
      final int port,
      final InetAddress localAddress,
      int localPort,
      final HttpParams params)
      throws IOException {

    if (host == null) {
      throw new IllegalArgumentException("Target host may not be null.");
    }
    if (params == null) {
      throw new IllegalArgumentException("Parameters may not be null.");
    }

    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {

      // we need to bind explicitly
      if (localPort < 0) localPort = 0; // indicates "any"

      InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
      sslsock.bind(isa);
    }

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress;
    if (this.nameResolver != null) {
      remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
    } else {
      remoteAddress = new InetSocketAddress(host, port);
    }
    try {
      sslsock.connect(remoteAddress, connTimeout);
    } catch (SocketTimeoutException ex) {
      throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
    }
    sslsock.setSoTimeout(soTimeout);
    try {
      hostnameVerifier.verify(host, sslsock);
      // verifyHostName() didn't blowup - good!
    } catch (IOException iox) {
      // close the socket before re-throwing the exception
      try {
        sslsock.close();
      } catch (Exception x) {
        /*ignore*/
      }
      throw iox;
    }

    return sslsock;
  }
コード例 #5
0
  @Override
  public Socket connectSocket(
      Socket sock,
      String host,
      int port,
      InetAddress localAddress,
      int localPort,
      HttpParams params)
      throws IOException, UnknownHostException, ConnectTimeoutException {
    if (host == null) {
      throw new IllegalArgumentException("Target host may not be null.");
    }
    if (params == null) {
      throw new IllegalArgumentException("Parameters may not be null.");
    }

    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {

      // we need to bind explicitly
      if (localPort < 0) {
        localPort = 0; // indicates "any"
      }

      InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
      sslsock.bind(isa);
    }

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress;
    remoteAddress = new InetSocketAddress(host, port);

    sslsock.connect(remoteAddress, connTimeout);

    sslsock.setSoTimeout(soTimeout);

    return sslsock;
  }
 @Override
 public Socket connectSocket(
     Socket sock,
     String host,
     int port,
     InetAddress localAddress,
     int localPort,
     HttpParams params)
     throws IOException {
   SSLSocket sslSocket = (SSLSocket) ((sock != null) ? sock : createSocket());
   if ((localAddress != null) || (localPort > 0)) {
     if (localPort < 0) {
       localPort = 0;
     }
     sslSocket.bind(new InetSocketAddress(localAddress, localPort));
   }
   sslSocket.connect(
       new InetSocketAddress(host, port), HttpConnectionParams.getConnectionTimeout(params));
   sslSocket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
   return sslSocket;
 }
コード例 #7
0
 public void bind(final SocketAddress bindpoint) throws IOException {
   delegate.bind(bindpoint);
 }