开发者

How do I use SSLSockets instead of standard Sockets with Java apps

开发者 https://www.devze.com 2023-03-20 21:39 出处:网络
I\'m trying to use ssl sockets in a working java networking program. I replaced two lines of code //Socket socket = new Socket(ipAddress, port);

I'm trying to use ssl sockets in a working java networking program.

I replaced two lines of code

        //Socket socket = new Socket(ipAddress, port);
        SSLSocket socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket(ipAddress, port);

and

        //serverSocket = new ServerSocket();
        serverSocket = (SSLServerSocket)SSLServerSocketFactory.getDefault().createServerSocket();

        serverSocket.setReuseAddress(true);
        serverSocket.bind(new InetSocketAddress(port));
        while (true) {
            Socket clientSocket = serverSocket.accept();
            ......

I get an exception: "connection refused: Connect"

The program was working with the commented code. And now it doesn't. What do I need to do to use SSLSockets instead of standard Sockets ?

If relevant, the server is running on localhost == windows v开发者_运维技巧ista.


'Connection refused' only has two meanings whether plaintext or SSL. There is nothing listening at the ip:port you tried to connect to, or an intermediate firewall explicitly blocked the connect by sending an RST.

Your second line of code creates an SSLServerSocket on an arbitrary port, because you left out the 'port' parameter. That's almost certainly the problem.


Bruno gave me the answer in the comments: I haven't configured any keystore.

0

精彩评论

暂无评论...
验证码 换一张
取 消