[英]socket.io : Receiving data from server node js
i created a node js server that emit data to html client using socket.io : 我创建了一个节点js服务器,该服务器使用socket.io向html客户端发送数据:
var spawn = require('child_process').spawn;
var child = spawn('node', ['file.js']);
child.stdin.write("Hello there!");
child.stdout.on('data', function (data) {
console.log('We received a reply: ' + data);
var listener = io.listen(server);
listener.sockets.on('connection', function(socket){
setTimeout(function(){
socket.emit('imageFromBlob', {'imageFromBlob': data});
}, 3000);
});
});
// Listen for any errors:
child.stderr.on('data', function (data) {
console.log('There was an error: ' + data);
});
server.listen(8001);
The data that i want to send to the client is a base 64 data, but when i run my server js, i'm getting in the browser : [object ArrayBuffer] but i want to get my data as is displayed when i do console.log(data). 我要发送到客户端的数据是基于64的数据,但是当我运行服务器js时,我正在浏览器中:[object ArrayBuffer],但我想获取控制台时显示的数据.log(数据)。
how can i extract the data as displayed when running my server from this ArrayBuffer? 从该ArrayBuffer运行服务器时,如何提取显示的数据?
您需要的是data.toString()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.