Search code examples
javassljsse

What does setUseClientMode mean


When I try to upgrade an exsisting Socket connection to a SSLSocket connection and I set setUseClientMode(true) then I get the error javax.net.ssl.SSLProtocolException: Handshake message sequence violation, 1 when calling mySSLSocket.startHandshake();. When not setting setUseClientMode() then everything works fine, and I can send and receive messages. I'm not asking for a fix, just what it means and what may be causing it.


Solution

  • It determines whether this side (a) sends or (b) expects to receive the initial handshake message, the ClientHello. If useClientMode is true, this side sends it. Don't set it at a server unless you really know what you're doing. If you're in a server and you are upgrading an accepted Socket you must set it to false. Otherwise there is really very little occasion to use it at all.

    NB useClientMode=true is the default.