-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
Connecting to ws:// I see 3% cpu usage. But when using SSL and connecting to wss:// I see 100% cpu usage. I can't reproduce locally so it's hard to know what's going on. I'm also using getSslContext() for a web server so I know it's correct.
try {
aSocketServer = new ASocketServer(443);
} catch (UnknownHostException e) {
e.printStackTrace();
}
try {
SSLContext sslContext = getSslContext();
if (sslContext != null) {
aSocketServer.setWebSocketFactory(new DefaultSSLWebSocketServerFactory(sslContext));
}
} catch (Exception e) {
e.printStackTrace();
}
public static SSLContext getSslContext() {
try {
final char[] pass = "pass".toCharArray();
final KeyStore keyStore = KeyStore.getInstance("JKS");
try (final InputStream is = new FileInputStream("file.jks")) {
keyStore.load(is, pass);
}
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, pass);
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom());
return sc;
} catch (KeyStoreException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | CertificateException | IOException exc) {
throw new RuntimeException(exc);
}
}
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.java_websocket.WebSocket;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import java.util.Date;
public class AsSocketServer extends WebSocketServer {
public ASocketServer( int port ) throws UnknownHostException {
super( new InetSocketAddress( port ) );
}
public ASocketServer( InetSocketAddress address ) {
super( address );
}
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
}
}