Dear stackoverflow forum,
I have a problem with the communication between my C-server and the client (javascript). I am using a Rasperry Pi 4 as server and Chrome as browser (I have also tested my stuff with Firefox and Edge).
My question is what the frame headers of the handshake look like. The handshake should change the communication protocol from HTTP to websocket. My headers look like this:
GET / HTTP/1.1
Host: 192.168.1.100:8000
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/119.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://192.168.1.100
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Sec-WebSocket-Key: 6Hw/S8rXFY4ExVDMGWWn6Q==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
The answer from the server (the code for generating the response request is attached):
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 57dCnQc8YJrJ51osdI/I71QHYi4=
Now I get the message in the browser:
script.js:8 WebSocket connection to 'ws://192.168.1.100:8000/' failed: Invalid frame header.
In wireshark, I can see that the frame headers look exactly as they do above. The browser (client) responds with a message highlighted in red: The reset flag is set on the response.
Does anyone see an error in the frame header? Or could the hash code be wrong?
Touby
Well I found a solution, I had a wrong handling of the incomming data. The data has to be decoded like this:
While a connection is active, you have to loop through this codelines until the connection is closed or you close it from server side.With this, there is no more invalid frame header.