我正在尝试通过'ws'网络套接字向服务器(运行nodejs)发送画布颜料。我无法弄清楚为什么我无法在服务器端接收blob文件。
服务器代码:
var WebSocketServer = require('ws').Server,
wss = new WebSocketServer({
port: 8080
});
wss.on('connection', function(ws) {
ws.on("message", function message(data, flags) {
console.log('received: %s', data;
}
});
});
客户代码:
var ws = new WebSocket("ws://127.0.0.1:8080");
timer = setInterval(
function() {
ctx.drawImage(video, 0, 0, 640, 480);
var data = canvas.get()[0].toDataURL('image/jpeg', 1.0);
var newblob = dataURItoBlob(data);
ws.send(newblob); //sending blob file
}, 50);