Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As far as the browser side, you can verify easily enough using chrome's dev tools. Look at the binary traffic and it will tell you if your sending binary of text frames. They are different kinds of frames in the websocket spec.</p> <p>On the node side, you can verify your buffer values are truly node buffers by using <code>Buffer.isBuffer()</code>. I see you're writing your buffer using the "binary" string encoding. This is probably not what you want. In node, the encoding for native <code>Buffer</code> instances is <code>null</code>. The <code>"binary"</code>, <code>"ascii"</code>, <code>"utf8"</code>, <code>"hex"</code>, <code>"base64"</code> encodings are all string encodings/decodings. What the binary encoding means is that every byte is stored in the string as a 8-bit unicode code point.</p> <pre><code>// Convert a binary buffer into a "binary" encoded string. function binaryEncode(buffer) { var string = ""; for (var i = 0, l = buffer.length; i &lt; l; i++) { string += String.fromCharCode(buffer[i]); } return string } // Convert a "binary" encoded string into a binary buffer. function binaryDecode(string) { var length = string.length; var buffer = new Buffer(length); for (var i = 0; i &lt; length; i++) { buffer[i] = string.charCodeAt(i); } } </code></pre> <p>Storing binary data can thus be done quite safely in JavaScript strings (which are defined as having 16 bit unicode code points per character). It's not the most efficient thing since you're wasting the upper 8 bits of every character and this is why node.js prefers native Buffers. But in things like browser crypto libraries, this "binary" string encoding is common since it is supported on all JS platforms.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload