<div>Hello!</div><div><br></div>Binary frames are actually supported, at least by chrome (and should be supported by any browser which implements at least hybi-07). <div><br></div><div>I got it working with cowboy and chrome by modifying the websocket_handler:websocket_info/3 from the cowboy websocket example:<div>
<br></div><div><div>websocket_info(tick, Req, State) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{reply, {binary, term_to_binary("Hello")}, Req, State, hibernate};</div></div><div>
<br></div><div>The browser receives a Blob which can be decoded by a FileReader object using readAsBinaryString followed by BERT-JS decode.</div><div><br></div><div>Sending from the browser is also not a problem. Converting the data from BERT-JS encoding requires you to convert it to an ArrayBuffer or Blob which introduces some extra steps, but it is doable.</div>
<div><br></div><div>Even though it's possible, I'd use JSON if the browser doesn't have to know how the data is represented in Erlang. For the project I'm working on, we came to the conclusion that if we used BERT, we had to do more work in JavaScript. If we used JSON, we had to do more work in Erlang.</div>
<div><br></div><div>Doing more work in Erlang is preferable, so we chose to go with JSON :)</div><div><br></div><div>/Erik Ylipää</div><div><div><br><div class="gmail_quote">2012/4/11 Ngoc Dao <span dir="ltr"><<a href="mailto:ngocdaothanh@gmail.com">ngocdaothanh@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for the info.<br>
<br>
About "websockets does not support binary data":<br>
* Wikipedia says "Binary frames are not supported yet in the API"<br>
("<a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">http://en.wikipedia.org/wiki/WebSockets</a>")<br>
* Stackoverflow says "until then, WebSockets payload is encoded as<br>
UTF-8" (<a href="http://stackoverflow.com/questions/5766802/send-and-receive-binary-data-over-web-sockets-in-javascript" target="_blank">http://stackoverflow.com/questions/5766802/send-and-receive-binary-data-over-web-sockets-in-javascript</a>)<br>
<br>
About BERT, it seems that BERT is not shorter than JSON, so I'm<br>
thinking of not using BERT.<br>
<br>
<br>
On Tue, Apr 10, 2012 at 11:17 PM, Antoine Koener<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:antoine.koener@gmail.com">antoine.koener@gmail.com</a>> wrote:<br>
> Here's a link: <a href="http://autobahn.ws/testsuite/reports/clients/index.html" target="_blank">http://autobahn.ws/testsuite/reports/clients/index.html</a><br>
><br>
> :-)<br>
><br>
> On Tue, Apr 10, 2012 at 3:54 PM, Antoine Koener<br>
> <<a href="mailto:antoine.koener@gmail.com">antoine.koener@gmail.com</a>> wrote:<br>
>> Are you sure that websockets does not support binary data ?<br>
>><br>
>> The data type is "blob", or "arraybuffer".<br>
>><br>
>> See w3c for more information.<br>
>><br>
>> (sorry for not giving you Uris about that, I'm conferencing :))<br>
>><br>
>> --<br>
>> Was in mobile mode ...<br>
>><br>
>> On 10 avr. 2012, at 04:26, ngocdaothanh <<a href="mailto:ngocdaothanh@gmail.com">ngocdaothanh@gmail.com</a>> wrote:<br>
>><br>
>>> What is the best way to use BERT encoding (<a href="http://bert-rpc.org/" target="_blank">http://bert-rpc.org/</a>) with<br>
>>> WebSocket?<br>
>>><br>
>>> BERT is binary but WebSocket does not support binary at this moment.<br>
>>> Should I use base64 to encode BERT binary to normal string? Base64 has<br>
>>> 33% overhead (<a href="http://en.wikipedia.org/wiki/Base64" target="_blank">http://en.wikipedia.org/wiki/Base64</a>). How much space can<br>
>>> BERT save compared to JSON?<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div></div>