![](/img/trans.png)
[英]Creating Node.js + socket.io Server/Client with users authentication, sending/receiving data
[英]socket.io : Receiving data from server node js
我創建了一個節點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);
我要發送到客戶端的數據是基於64的數據,但是當我運行服務器js時,我正在瀏覽器中:[object ArrayBuffer],但我想獲取控制台時顯示的數據.log(數據)。
從該ArrayBuffer運行服務器時,如何提取顯示的數據?
您需要的是data.toString()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.