Websocket messages after handshake

898 views Asked by At

I made websocket communication on my server, in C++. I have a problem with websocket protocol. When I get handshake message in text format, I make handshake response and send back in text format and connection is opened, but when I sending back second message to browser the connection fails. But if I put handshake answer in frame on first message, everything works fine later, I don't have a problem with other messages.

Mozzila firefox: The connection to ws://localhost/ was interrupted while the page was loading. Google chrome: WebSocket connection to 'ws://localhost/' failed: A server must not mask any frames that it sends to the client.

I don't mask any frames.

This works on Mozzila firefox and google chrome, but doesn't work on safari. So, does anyone know what the problem is? Did anyone have this problem?

Thanks

1

There are 1 answers

0
KuroUsagi962 On

You say you are not masking any frames (From server to client), in the data that you are sending back, please check the first bit of the second byte.

According to RFC6445 the first bit of the second byte (The mask flag) MUST be set to 0 when sending data to the client. If your frame isn't set correctly and that bit is set to 1, the browser is going to complain about "A server must not mask any frames that it sends to the client"

Also this may be irrelevant to you, but check that you don't have any trailing data in the upgrade/handshake part of code, when working on Web Sockets, having a trailing chr(0) (Null character) caused issues for me later on when I was trying to send the client data.