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


Java SSLSocket.close方法代碼示例

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


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

示例1: check_nickname

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
public boolean check_nickname(String nickname) throws ClassNotFoundException
{
    //connect to Registrar to check if nickname is unique
    boolean check = false;
    try 
    {
        
        SSLSocket sslSocket=Client.get_SSLSock();
        //Socket s1 = new Socket("localhost", 5999);
        ObjectOutputStream out = new ObjectOutputStream(sslSocket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(sslSocket.getInputStream());

        out.writeObject(new Message(nickname, "null"));//here goes nickname
        out.flush();
        
        check = (boolean)in.readObject();

        sslSocket.close();
    } catch (IOException ex) {
        Logger.getLogger(NewConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    return check;
}
 
開發者ID:georgemakrakis,項目名稱:TrackMeIfYouCanChat,代碼行數:25,代碼來源:Nickname.java

示例2: handleClient

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
private static void handleClient(SSLSocket sslSocket) throws IOException {
    String clientType;
    try {
        clientType = new Transmission(sslSocket).readText();
    } catch (IOException e) {
        Logger.log("Failed retreiving text from " + sslSocket.getInetAddress().getHostAddress() + ", problably not a secure connection, aborting.");
        sslSocket.close();
        return;
    }
    if (clientType.toUpperCase().equals("SENDER")) {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " is a sender.");
        handleSender(sslSocket);
    } else if (clientType.toUpperCase().equals("RECEPTOR")) {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " is a receptor.");
        handleReceptor(sslSocket);
    } else {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " isn't a secure connection, aborting connection.");
        sslSocket.close();
    }
}
 
開發者ID:luisbraganca,項目名稱:file-transfer,代碼行數:21,代碼來源:Main.java

示例3: doServerSide

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf =
        (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslssf.createServerSocket(serverPort);

    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    InputStream sslIS = sslSocket.getInputStream();
    OutputStream sslOS = sslSocket.getOutputStream();

    sslIS.read();
    sslOS.write('A');
    sslOS.flush();

    sslSocket.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:GenericBlockCipher.java

示例4: doClientSide

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLSocketFactory sslsf =
            (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslSocket = (SSLSocket)
            sslsf.createSocket("localhost", serverPort);

        // enable TLSv1.1 only
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});

        // enable a stream cipher
        sslSocket.setEnabledCipherSuites(
            new String[] {"SSL_RSA_WITH_RC4_128_MD5"});

        InputStream sslIS = sslSocket.getInputStream();
        OutputStream sslOS = sslSocket.getOutputStream();

        sslOS.write('B');
        sslOS.flush();
        sslIS.read();

        sslSocket.close();
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:GenericStreamCipher.java

示例5: retryableSSLHandshakeException

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Test
public void retryableSSLHandshakeException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  boolean retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertTrue(retry);
  socket.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:ConnectionSpecSelectorTest.java

示例6: processHandshakeFailure

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
private void processHandshakeFailure(Socket raw) throws Exception {
  SSLContext context = SSLContext.getInstance("TLS");
  context.init(null, new TrustManager[] {UNTRUSTED_TRUST_MANAGER}, new SecureRandom());
  SSLSocketFactory sslSocketFactory = context.getSocketFactory();
  SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(
      raw, raw.getInetAddress().getHostAddress(), raw.getPort(), true);
  try {
    socket.startHandshake(); // we're testing a handshake failure
    throw new AssertionError();
  } catch (IOException expected) {
  }
  socket.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:MockWebServer.java

示例7: nonRetryableIOException

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Test
public void nonRetryableIOException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  boolean retry = connectionSpecSelector.connectionFailed(
      new IOException("Non-handshake exception"));
  assertFalse(retry);
  socket.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:ConnectionSpecSelectorTest.java

示例8: nonRetryableSSLHandshakeException

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Test
public void nonRetryableSSLHandshakeException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  SSLHandshakeException trustIssueException =
      new SSLHandshakeException("Certificate handshake exception");
  trustIssueException.initCause(new CertificateException());
  boolean retry = connectionSpecSelector.connectionFailed(trustIssueException);
  assertFalse(retry);
  socket.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:ConnectionSpecSelectorTest.java

示例9: someFallbacksSupported

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Test
public void someFallbacksSupported() throws Exception {
  ConnectionSpec sslV3 =
      new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
          .tlsVersions(TlsVersion.SSL_3_0)
          .build();

  ConnectionSpecSelector connectionSpecSelector = createConnectionSpecSelector(
      ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS, sslV3);

  TlsVersion[] enabledSocketTlsVersions = {TlsVersion.TLS_1_1, TlsVersion.TLS_1_0};
  SSLSocket socket = createSocketWithEnabledProtocols(enabledSocketTlsVersions);

  // MODERN_TLS is used here.
  connectionSpecSelector.configureSecureSocket(socket);
  assertEnabledProtocols(socket, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);

  boolean retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertTrue(retry);
  socket.close();

  // COMPATIBLE_TLS is used here.
  socket = createSocketWithEnabledProtocols(enabledSocketTlsVersions);
  connectionSpecSelector.configureSecureSocket(socket);
  assertEnabledProtocols(socket, TlsVersion.TLS_1_0);

  retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertFalse(retry);
  socket.close();

  // sslV3 is not used because SSLv3 is not enabled on the socket.
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:ConnectionSpecSelectorTest.java

示例10: doClientSide

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLContext context = generateSSLContext(true);
        SSLSocketFactory sslsf = context.getSocketFactory();

        SSLSocket sslSocket =
            (SSLSocket)sslsf.createSocket("localhost", serverPort);

        try {
            sslSocket.setSoTimeout(5000);
            sslSocket.setSoLinger(true, 5);

            InputStream sslIS = sslSocket.getInputStream();
            OutputStream sslOS = sslSocket.getOutputStream();

            sslOS.write('B');
            sslOS.flush();
            sslIS.read();

            throw new Exception("EC curve secp224k1 should be disabled");
        } catch (SSLHandshakeException she) {
            // expected exception: Received fatal alert
            System.out.println("Expected exception: " + she);
        } finally {
            sslSocket.close();
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:ECCurvesconstraints.java

示例11: doServerSide

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf =
        (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslssf.createServerSocket(serverPort);

    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    InputStream sslIS = sslSocket.getInputStream();
    OutputStream sslOS = sslSocket.getOutputStream();

    boolean interrupted = false;
    try {
        sslIS.read();
        sslOS.write('A');
        sslOS.flush();
    } catch (IOException ioe) {
        // get the expected exception
        interrupted = true;
    } finally {
        sslSocket.close();
    }

    if (!interrupted) {
        throw new SSLHandshakeException(
            "A weak cipher suite is negotiated, " +
            "TLSv1.1 must not negotiate the exportable cipher suites.");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:ExportableStreamCipher.java

示例12: cleanUpFailedSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
 * Do any cleanup necessary due to socket creation failure (e.g. due to hostname validation failure).
 * 
 * @param sslSocket the {@link SSLSocket} to cleanup
 */
protected void cleanUpFailedSocket(SSLSocket sslSocket) {
    try {
        sslSocket.close();
    } catch (IOException e) {
        // Do nothing. We haven't returned it yet, so can just ignore.
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:TLSProtocolSocketFactory.java

示例13: verifyHostname

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException {
    try {
        this.hostnameVerifier.verify(hostname, sslsock);
        // verifyHostName() didn't blowup - good!
    } catch (final IOException iox) {
        // close the socket before re-throwing the exception
        try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
        throw iox;
    }
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:11,代碼來源:SSLConnectionSocketFactory.java

示例14: Heartbeat

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
public Heartbeat(String nickname,String i2p_dest)
{
    try 
    {
        SSLSocket sslSocket=Client.get_SSLSock();
        
        //Socket s1 = new Socket("localhost", 5999);
        ObjectOutputStream out = new ObjectOutputStream(sslSocket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(sslSocket.getInputStream());
        
        
        Message msg = new Message();
        msg.set_name(Client.nickname);
        msg.set_HB();
        out.writeObject(msg);//here goes i2p_dest for heartbeat
        out.flush();
        
        String check = (String)in.readObject();//Read string to know what to do next
        if (check.equals("ArrayList"))
        {
            ar1 = (ArrayList<Message>) in.readObject();
            for (int i=0;i<ar1.size();i++)//remove curent user from list
            {
                if(ar1.get(i).get_i2p_dest().equals(i2p_dest))
                {
                    ar1.remove(i);
                }
            }
            System.out.println("Received HeartBeat");
            System.out.print("Users:");
            for (int i = 0; i < ar1.size(); i++) {
                System.out.print(" " + ar1.get(i).get_nickname());
            }
            System.out.println();
            Client.model1.removeAllElements();//remove all users from model1
            for (int i = 0; i < ar1.size(); i++) {
                Client.model1.addElement(ar1.get(i).get_nickname());//add all active users
            }
            Client.users=ar1;
        }
        else
        {
            Client.registered=false;//Set that client is not registered in Registrar
            new NewConnection(nickname, i2p_dest);
        }
        
        sslSocket.close();
    } catch (IOException | ClassNotFoundException ex) 
    {
        ex.printStackTrace();
    }
}
 
開發者ID:georgemakrakis,項目名稱:TrackMeIfYouCanChat,代碼行數:53,代碼來源:Heartbeat.java

示例15: 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


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