如果 SSLSocket.startHandshake() 是同步的,为什么要提供回调?

Why does SSLSocket.startHandshake() offers a callback if it is synchronous ?

方法 SSLSocket.startHandshake() 的 javadoc 说该方法是同步的。

但是,"see also" 部分提供了 "handshakeComplete" 事件的回调:HandshakeCompletedListener

如果方法 returns 在握手完成后立即进行回调,为什么会有这样的回调?

是否意味着如果我写这段代码

SSLSocket c = (SSLSocket) f.createSocket("localhost", 8888);
c.startHandshake();

BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
c.getOutputStream()));
BufferedReader r = new BufferedReader(new InputStreamReader(
c.getInputStream()));
w.write("I am client " + UUID.randomUUID().toString());
w.newLine();

我不能保证只在握手完成后写入outputStream?

Why does SSLSocket.startHandshake() offers a callback if it is synchronous?

它并不总是同步的。

The javadoc for method SSLSocket.startHandshake() says that the method is synchronous.

不,不是。它说它是同步的 用于初始握手。

However, the "see also" section offers a callback for the "handshakeComplete" event : HandshakeCompletedListener.

正确。

Why would it be useful to have such a callback if the method returns right after the handshake is completed?

不合逻辑。。回调总是有用的,并且该方法并不总是在握手完成后立即 return。

查看 Javadoc。