I am using websockify
to display images from a python server to a HTML5 canvas.
I think that I have manage to successfully send images from my python server but I am not able to display the images to my canvas.
I think the problem has to do with the number of bytes that I am trying to display on canvas and I believe that I am not waiting until the whole image is received and then displaying the image to the canvas.
Until now I have:
The on message function. When I sent an image I get 12 MESSAGERECEIVED
in console
ws.on('message', function () {
//console.log("MESSAGERECEIVED!")
msg(ws.rQshiftStr());
});
The msg function where I receive the string and I am trying to display it on canvas. I invoking the method 12 times for each picture. The format of the sting is 'xÙõKþ°pãüCY
:
function msg(str) {
//console.log(str);
console.log("RELOAD");
var ctx = cv.getContext('2d');
var img = new Image();
//console.log(str);
img.src = "data:image/png;base64," + str;
img.onload = function () {
ctx.drawImage(img,0,0);
}
}
Any suggestions on how to fix this?