Is there a way make the SSLSocket wait until the handshake is completed without using the addHandshakeListener() method? I would like it to block until it has completed the handshake.
Edit:
A little bit more clarification: a regular (Non-SSL) Socket is initially used (this is required, because a package must be sent to the server before the actual handshake takes place). This socket is “converted” into a SSLSocket using SSlSocketFactory.createSocket.
My question is that whether there is a way to now synchronously do the handshake.
SSLSocket.startHandshake() is a synchronous call when you start handshake between the peers very first time, it will block the calling thread until handshake has completed:
This is not fully documented in Android API, see original Java API for the complete javadoc:
The situation becomes pretty complicated if you manipulate handshake multiple times between the peers, it could be an asynchronous call in some cases (when you need Listener), check out this online document Fundamental Networking in Java for more details.