Code example for SSLServerSocketFactory

Methods: createServerSocket

0
    private SSLServerSocket serverSocket = null;
 
    public SSLServer() throws Exception { 
        // 通过套接字工厂,获取一个服务器端套接字 
        SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
        serverSocket = (SSLServerSocket) socketFactory.createServerSocket(7070);
    } 
 
    private void runServer() { 
        while (true) { 
            try { 
                System.out.println("Waiting for connection...");
                // 服务器端套接字进入阻塞状态,等待来自客户端的连接请求 
                SSLSocket socket = (SSLSocket) serverSocket.accept();
 
                // 获取服务器端套接字输入流 
                BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                // 从输入流中读取客户端用户名和密码 
                String userName = input.readLine();
                String password = input.readLine();
Experience pair programming with AI  Get Codota for Java