Java Socket

比较经典的用法,使用ServerSocket构建服务端,用accpet的方法,阻塞式的等待Socket请求。通常使用多线程对Socket进行消费。

NIO进行Socket编程,可以注册Selector,并且注册到channel中,用观察者模式,做到单线程的方式消费Socket。

 

        SSLSocket

 

String trustStore = config.getTrustStore();
String trustStorePwd = config.getTrustStorePassword();
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePwd);

SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) factory.createSocket();
String suiteString = getSSLCipherSuites();
if (!StringUtils.isEmpty(suiteString)) {
    log.info("SSL Cipher Suites:" + suiteString);
    String[] suites = suiteString.trim().split(",");
    sslsocket.setEnabledCipherSuites(suites);
}

你可能感兴趣的:(java,socket,ssl)