(Sorry, I was just going to comment on EJP's now-deleted answer.)
The server code says:
SSLSocket c = (SSLSocket)sslSock.accept();
PrintWriter out =new PrintWriter(c.getOutputStream(),true);
InputStream in = c.getInputStream();
in.close();
out.close();
That is, the I/O streams (and thus the socket) are closed immediately after the socket is accepted. Hence, an error message appearing on the client saying that the connection has been closed by the remote party shouldn't really come as a surprise.
This more or less the same problem as in this question: just getting the I/O streams, without trying to read/write from them, and without trying any other action that triggers the handshake implicitly (reading from the streams or trying to get the SSLSession
) or explicitly (calling startHandshake
) means that the handshake won't have started on the server. Therefore, the client throws this exception because the connection is interrupted in the middle of the handshake it has started.