Nio-ssl: what happens if you write before the handshake completes?

when establishing a TCP+SSL connection, the handler gets a handshakeCompleted(negotiatedProtocol: nil) event. what happens if i call channel.writeAndFlush before the handshake completes? is it possible for this to fail?

so far, it seems to be working, but i don’t know if that’s just because the writeAndFlush call is asynchronous, and isn’t actually executing until after the handshake completes.

The write will be queued until the handshake completes, and will be flushed to the network when it does.

Yes, if the handshake does not complete successfully or an error occurs when attempting to flush the application data.

NIOSSL (and NIO Transport Services) both explicitly tolerate this mode of operation, because it’s extremely difficult to ask users to hold on to initial data they have floating around. So you’re entirely safe and doing the supported thing.

3 Likes
Terms of Service

Privacy Policy

Cookie Policy