I'm having nodejs websocket server and client to send images. Problem is client auto disconnects on sending high resolution [i.e 512 x 512 or more] or large size [i.e nearly > 50KB]images.
Note: With lesser dimensions and size it's able to send.
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
}
function sendImage(){
var img = getBase64Image(document.getElementById("image") );
var JSONimg = {
' type' : 'img',
'data' : img,
}
ws.send(JSON.stringify(JSONimg));
}
Corresponding HTML:
<button onclick="sendImage()">Send Image</button>
<img id="image" src="img/image.png" alt="" />
Question
Is Size or dimension of image is a reason for socket disconnection?
Any Size limitation for websocket messages?