當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLSocket.connect方法代碼示例

本文整理匯總了Java中javax.net.ssl.SSLSocket.connect方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLSocket.connect方法的具體用法?Java SSLSocket.connect怎麽用?Java SSLSocket.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.SSLSocket的用法示例。


在下文中一共展示了SSLSocket.connect方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doInBackground

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(Void... params) {
    try {
        // TODO: support self-defined ports instead of 443 only
        SocketFactory factory = SSLSocketFactory.getDefault();
        SSLSocket socket = (SSLSocket) factory.createSocket();
        socket.connect(new InetSocketAddress(oasp_url.substring(8), 443), CON_TIMEOUT);
        socket.startHandshake();
        Certificate[] certs = socket.getSession().getPeerCertificates();
        socket.close();
        if (certs == null)
            return false;

        for (Certificate cert : certs) {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA256");
            messageDigest.update(cert.getEncoded());
            oasp_url_certs.add(convertToHex(messageDigest.digest()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
開發者ID:baidu,項目名稱:OASP,代碼行數:25,代碼來源:OASPVerify.java

示例2: createSSLSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
public SSLSocket createSSLSocket(InetAddress address, int port,
        InetAddress myAddress) throws IOException {
	SSLSocket sock = (SSLSocket) sslSocketFactory.createSocket();
	if (myAddress != null) {
 	// trying to bind to the correct ipaddress (in case of multiple vip addresses by example)
 	// and let the JDK pick an ephemeral port
 	sock.bind(new InetSocketAddress(myAddress, 0));
	}
	try {
		sock.connect(new InetSocketAddress(address, port), 8000);
	} catch (SocketTimeoutException e) {
		throw new ConnectException("Socket timeout error (8sec)" + address + ":" + port);
	}
	return sock;
}
 
開發者ID:YunlongYang,項目名稱:LightSIP,代碼行數:16,代碼來源:SslNetworkLayer.java

示例3: createSSLSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
public SSLSocket createSSLSocket(InetAddress address, int port,
        InetAddress myAddress) throws IOException {
	SSLSocket sock = (SSLSocket) sslSocketFactory.createSocket();
	if (myAddress != null) {
		// trying to bind to the correct ipaddress (in case of multiple vip addresses by example)
		// and let the JDK pick an ephemeral port
		sock.bind(new InetSocketAddress(myAddress, 0));
	}
	try {
		sock.connect(new InetSocketAddress(address, port), 8000);
	} catch (SocketTimeoutException e) {
		throw new ConnectException("Socket timeout error (8sec)" + address + ":" + port);
	}
	return sock;
}
 
開發者ID:YunlongYang,項目名稱:LightSIP,代碼行數:16,代碼來源:DefaultNetworkLayer.java

示例4: connectSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Override
public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {

    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock :
            createSocket(context));
    if (localAddress != null) sslsock.bind(localAddress);


    sslsock.connect(remoteAddress, connectTimeout);
    // socket timeout is set internally by the
    // PoolingHttpClientConnectionManager.
    return sslsock;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:14,代碼來源:ApacheConnectionManagerFactory.java

示例5: connectSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Override
public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket(context));
    if (localAddress != null) {
        InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(),
                localAddress.getPort());
        sslsock.bind(isa);
    }
    sslsock.connect(remoteAddress, connectTimeout);
    return sslsock;
}
 
開發者ID:1991wangliang,項目名稱:lorne_core,代碼行數:12,代碼來源:EasySSLConnectionSocketFactory.java

示例6: connectSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
 * @since 4.1
 */
public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException
{
	if (remoteAddress == null)
	{
		throw new IllegalArgumentException("Remote address may not be null");
	}

	if (params == null)
	{
		throw new IllegalArgumentException("HTTP parameters may not be null");
	}

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

	if (localAddress != null)
	{
		//            sslSocket.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
		sslSocket.bind(localAddress);
	}

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

	try
	{
		sslSocket.connect(remoteAddress, connTimeout);
	}
	catch (SocketTimeoutException ex)
	{
		throw new ConnectTimeoutException(String.format("Connect to %s/%s timed out", remoteAddress.getHostName(), remoteAddress.getAddress()));
	}

	sslSocket.setSoTimeout(soTimeout);

	if (this.hostnameVerifier != null)
	{
		try
		{
			this.hostnameVerifier.verify(remoteAddress.getHostName(), sslSocket);
			// verifyHostName() didn't blowup - good!
		}
		catch (IOException iox)
		{
			// close the socket before re-throwing the exception
			try
			{
				sslSocket.close();
			}
			catch (Exception x)
			{ /*ignore*/ }
			throw iox;
		}
	}

	return sslSocket;
}
 
開發者ID:ultrasonic,項目名稱:ultrasonic,代碼行數:60,代碼來源:SSLSocketFactory.java

示例7: connectSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@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)) {
		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;
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:43,代碼來源:MySSLSocketFactory.java


注:本文中的javax.net.ssl.SSLSocket.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。