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


Java SSLServerSocket.close方法代碼示例

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


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

示例1: assertSSLServerSocketFactoryConfigSameAsSSLContext

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
/**
 * Asserts that {@link SSLServerSocketFactory}'s configuration matches {@code SSLContext}'s
 * configuration, and that {@link SSLServerSocket} instances obtained from the factory match
 * this
 * configuration as well.
 */
private static void assertSSLServerSocketFactoryConfigSameAsSSLContext(
        SSLServerSocketFactory sslServerSocketFactory, SSLContext sslContext)
        throws IOException {
    assertCipherSuitesEqual(sslContext.getDefaultSSLParameters().getCipherSuites(),
            sslServerSocketFactory.getDefaultCipherSuites());
    assertCipherSuitesEqual(sslContext.getSupportedSSLParameters().getCipherSuites(),
            sslServerSocketFactory.getSupportedCipherSuites());
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslServerSocketFactory.createServerSocket();
    try {
        assertFalse(sslServerSocket.getUseClientMode());
        assertTrue(sslServerSocket.getEnableSessionCreation());
        assertSSLServerSocketConfigSameAsSSLContext(sslServerSocket, sslContext);
    } finally {
        sslServerSocket.close();
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:24,代碼來源:SSLConfigurationAsserts.java

示例2: open

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
@Override
public ServerChannel open(InetAddress address, int port, int timeout)
        throws IOException
{
    SSLServerSocket sock =
        (SSLServerSocket) _factory.createServerSocket(port,
                                                      _backlog, address);
    try {
        sock.setReuseAddress(_isReuseAddress);
        sock.setWantClientAuth(_isWantClientAuth);
        return new SSLServerChannel(sock, timeout);
    } catch (Throwable t) {
        if (!sock.isClosed()) {
            try {
                sock.close();
            } catch (Throwable tt) {
                t.addSuppressed(tt);
            }
        }
        throw t;
    }
}
 
開發者ID:perlundq,項目名稱:yajsync,代碼行數:23,代碼來源:SSLServerChannelFactory.java

示例3: doServerSide

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
void doServerSide() throws Exception {
    SSLContext context = generateSSLContext(false);
    SSLServerSocketFactory sslssf = context.getServerSocketFactory();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket)sslssf.createServerSocket(serverPort);
    serverPort = sslServerSocket.getLocalPort();

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

    SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
    try {
        sslSocket.setSoTimeout(5000);
        sslSocket.setSoLinger(true, 5);

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

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

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

示例4: doServerSide

import javax.net.ssl.SSLServerSocket; //導入方法依賴的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 = null;
    try {
        sslSocket = (SSLSocket) sslServerSocket.accept();
        sslSocket.setSoTimeout(TIMEOUT);
        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());

        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (sslSocket != null) { sslSocket.close(); }
            sslServerSocket.close();
        } catch (IOException unused)  {  /* gulp!burp! */   }
    }
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:30,代碼來源:CookieHttpsClientTest.java

示例5: run

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
public void run() {
    try {
        store = provideKeys ? getKeyStore(keys) : null;
        KeyManager[] keyManagers = store != null ? getKeyManagers(store) : null;
        TrustManager[] trustManagers = new TrustManager[] { trustManager };

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagers, trustManagers, null);

        SSLServerSocket serverSocket = (SSLServerSocket)sslContext
                .getServerSocketFactory().createServerSocket();

        if (clientAuth == CLIENT_AUTH_WANTED) {
            serverSocket.setWantClientAuth(true);
        } else if (clientAuth == CLIENT_AUTH_NEEDED) {
            serverSocket.setNeedClientAuth(true);
        } else {
            serverSocket.setWantClientAuth(false);
        }

        serverSocket.bind(new InetSocketAddress(port));

        SSLSocket clientSocket = (SSLSocket)serverSocket.accept();

        InputStream istream = clientSocket.getInputStream();
        byte[] buffer = new byte[1024];
        istream.read(buffer);

        OutputStream ostream = clientSocket.getOutputStream();
        ostream.write(testData.getBytes());
        ostream.flush();

        while (notFinished) {
            Thread.currentThread().sleep(500);
        }

        clientSocket.close();
        serverSocket.close();

    } catch (Exception ex) {
        exception = ex;
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:44,代碼來源:SSLSessionTest.java

示例6: run

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
public void run() {
    try {
        KeyManager[] keyManagers = provideKeys ? getKeyManagers(keys) : null;
        TrustManager[] trustManagers = new TrustManager[] { trustManager };

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagers, trustManagers, null);

        SSLServerSocket serverSocket = (SSLServerSocket)sslContext.getServerSocketFactory().createServerSocket();

        if (clientAuth == CLIENT_AUTH_WANTED) {
            serverSocket.setWantClientAuth(true);
        } else if (clientAuth == CLIENT_AUTH_NEEDED) {
            serverSocket.setNeedClientAuth(true);
        } else {
            serverSocket.setWantClientAuth(false);
        }

        serverSocket.bind(new InetSocketAddress(port));

        SSLSocket clientSocket = (SSLSocket)serverSocket.accept();

        InputStream istream = clientSocket.getInputStream();

        for (int i = 0; i < 256; i++) {
            int j = istream.read();
            if (i != j) {
                throw new RuntimeException("Error reading socket, expected " + i + ", got " + j);
            }
        }

        istream.close();

        OutputStream ostream = clientSocket.getOutputStream();

        for (int i = 0; i < 256; i++) {
            ostream.write(i);
        }

        ostream.flush();
        ostream.close();

        clientSocket.close();
        serverSocket.close();

    } catch (Exception ex) {
        exception = ex;
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:50,代碼來源:HandshakeCompletedEventTest.java


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