我正在使用node.js BinaryServer来流式传输二进制数据,并且我想在客户端调用.Stream.end()
函数后从服务器发起回调事件。Node.js BinaryServer:在流结束时向客户端发送消息?
我似乎无法理解 - 当node.js服务器实际关闭流连接时,如何发送消息或某种通知?
节点JS:
server.on('connection', function(client) {
client.on('stream', function (stream, meta) {
stream.on('end', function() {
fileWriter.end();
// <--- I want to send an event to the client here
});
});
});
客户端JS:
client = new BinaryClient(nodeURL);
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
// <--- I want to recieve the callback message
上的节点JS的一面,你可以试试'client.send( “结束”)' –
@ExplosionPills而我应该在客户端做什么? –
收听'stream'事件,'client.on(“stream”,data =>/*对数据做一些操作* /)' –