I'm having some issues decoding data sent over websockets from Chrome (JavaScript) to a python server (using low-level socket apis). I've handled the handshake properly, the readyState
of the websocket is OPEN when I use .send(...)
. I receive byte data (per the specs), but no matter how I try to decode it, it comes out as jibberish or triggers an exception.
javascript
var we = new WebSocket(url);
we.send("string data");
python
data = socket.recv(1024) # socket from sock.accept(...)
#handle data
I've tried data.decode('utf-8')
as that seems like it would be the obvious solution (throws an error). I've tried stripping \x80
and \x81
(I think - I read it somewhere on StackOverflow), but it still throws an error...
I've tried base64 decoding - which I found in an answer here on SO (but that doesn't make sense so...)
Anything I'm missing?