简体   繁体   English

socket.io:从服务器节点js接收数据

[英]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.

相关问题 使用用户身份验证创建Node.js + socket.io服务器/客户端,发送/接收数据 - Creating Node.js + socket.io Server/Client with users authentication, sending/receiving data Socket.io从Node中的多个套接字接收数据 - Socket.io receiving data from multiple sockets in Node Socket.io客户端无法正确从服务器接收数据 - Socket.io Client Not Receiving Data from Server Correctly 从JAVA向node.js / socket.io服务器发送数据 - sending data to node.js/socket.io server from JAVA 如何使用 socket.io 在客户端(网络浏览器)中显示来自 node.js 服务器的实时数据? - How to use socket.io to display realtime data in the client (web browser) from the node.js server? 如何从Node.js socket.io服务器向浏览器客户端发送二进制数据? - How to send binary data from a Node.js socket.io server to a browser client? 以gzip格式从node.js服务器向客户端发送socket.io响应数据 - Send socket.io response data to client from node.js server in gzip format 如何将数据从 mysql 服务器发送到 node.js socket.io - how to emit data from mysql server to node.js socket.io 不使用socket.io和node.js发出/接收事件 - Not emitting/receiving events with socket.io and node.js Node.js + Socket.io:客户端未收到消息 - Node.js + Socket.io: Client not receiving message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM