Error in order of extension handshake messages and wrong byte order in length field of extension handshake request message

  • Order of the extension handshake request/response,

The order shouldn’t matter. Either peer can send the handshake first. Here’s a related explanation that might help clarify.


The issue seems to be caused by clearReadBuffer:

I’m not sure why it’s there, but if I comment it out, and rearrange doExtendedHandshake, your code still works:

Let me know if you’d like further assistance!