本文整理汇总了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();
}
}
示例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;
}
}
示例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();
}
}
示例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! */ }
}
}
示例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;
}
}
示例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;
}
}