0

我有以下代码用于使用套接字并通过 https 进行连接:

public static void main(String[] argv) throws Exception {
    SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(8080);
    String[] suites = serverSocket.getSupportedCipherSuites();
    for (int i = 0; i < suites.length; i++) {
        System.out.println(suites[i]);
    }
    serverSocket.setEnabledCipherSuites(suites);
    String[] protocols = serverSocket.getSupportedProtocols();
    for (int i = 0; i < protocols.length; i++) {
        System.out.println(protocols[i]);
    }
    while (!serverSocket.isClosed()) {
        SSLSocket socket = (SSLSocket) serverSocket.accept();
        socket.startHandshake();
        DataOutputStream ClienteEscribir = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
        ClienteEscribir.write("Hi".getBytes());

        ClienteEscribir.close();
        socket.close();
    }
    serverSocket.close();
}

每次客户端连接时,我都会收到此错误:

SSLv2Hello
SSLv3
TLSv1
TLSv1.1
TLSv1.2
Exception in thread "main" javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:541)
    at sun.security.ssl.InputRecord.read(InputRecord.java:374)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305)
    at Main.main(Main.java:21)
Java Result: 1

任何想法?

4

0 回答 0