Skip to content Skip to sidebar Skip to footer

Compressed Bit Must Be 0 When Sending A Message To Websocket Client

I'm writing a websocket server in python, and I've run into a problem when sending messages back to the client. Using chrome's javascript console, I can get as far as finding this

Solution 1:

This is the same answer as for your other question: WebSocket onmessage not firing

You're problem is that you are using the bytes function in python 2.X but expecting it to work the way it does in python 3.X

python2.6.6:

>>> bytes([129, 19])
'[129, 19]'

python 3:

>>> bytes([129, 19])
b'\x81\x13'

By replacing the send with the following in your server code it works for me in python2.X:

client_socket.send( "".join( [chr(c) for c in formatted_bytes] )

A couple of other notes:

  • The code you linked to is adding 1 to the message length which is incorrect.

  • You should really have the handshake code separate from the normal message parsing code. If somebody happened to send a message which contained "Sec-WebSocket-Key: " you would end up corrupting the stream by sending a raw handshake back again.

Post a Comment for "Compressed Bit Must Be 0 When Sending A Message To Websocket Client"