I am using python SimpleWebSocketServer, with a modified SimpleExample.py
and Chrome.
Everything works fine when I send strings from browser to python, but when I send string from python to browser, I don't have the faintest idea how to transform the received ArrayBuffer (or Blob, if configured so) into a javascript string.
Python code:
def handleConnected(self):
with open("roads.txt") as roadsfile:
content = "" + roadsfile.read()
self.sendMessage(content)
Browser code:
function doConnect() {
websocket = new WebSocket("ws://localhost:8000/");
websocket.binaryType = 'arraybuffer';
websocket.onmessage = function(event) { onMessage(event) };
}
function onMessage(event) {
console.log(event.data);
}
And what's get logged is just ArrayBuffer{}
, appearing to be empty, I guess.
I don't know what to do with this ArrayBuffer, neither how to check for its validity.
By the way, the file content from roads.txt
is one long line of text-based floats, similar to .csv, so if I could encode them as an actual binary array, the better!