[Libwebsockets] regarding getting binary data in javascript web client

Suman.Patro-TRN Suman.Patro-TRN at lntebg.com
Tue Jul 12 10:54:21 CEST 2016

Thanks Rob.
I tried with your approach but I am still unable to display data on my javascript client. I understand that the browser is able to fetch the  data but the only problem is in the representation.
At the server side , I have mere written LWS_WRITE_BINARY in lws_write the same way as that of LWS_WRITE_TEXT and when sniffing using wireshark , I understand data is being sent from the server and the javascript client receives a "Binary Frame (Opcode 2)" and not the actual message.
At the javascript end:the code for get message and displaying of the same is written as follows:

socket_di.binaryType = 'arraybuffer';

                socket_di.onmessage =function got_packet(msg) {
                var buffer = new ArrayBuffer( msg.length );
    var view   = new Uint8Array( buffer );
    var len    = view.length;
    var fromCharCode = String.fromCharCode;
    var i, s, str="";

                for ( i = 0; i < len; ++i ) {
  str += fromCharCode( res[i].charCodeAt(0) & 0xff );
                document.getElementById("recv_msg").textContent = str+ "\n";

But still I do not get any output on the recv_msg text box. What is the thing that I am missing?
Thanks and regards,

Larsen & Toubro Limited


This Email may contain confidential or privileged information for the intended recipient (s). If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20160712/97b4b382/attachment-0001.html>

More information about the Libwebsockets mailing list