Javascript Node.js BinaryServer:是否在流端向客户端发送消息?
我正在使用node.js BinaryServer来流式传输二进制数据,我希望在客户端调用Javascript Node.js BinaryServer:是否在流端向客户端发送消息?,javascript,node.js,Javascript,Node.js,我正在使用node.js BinaryServer来流式传输二进制数据,我希望在客户端调用.Stream.end()函数后,从服务器上获得一个回调事件 我似乎不明白-当node.js服务器实际关闭流连接时,我如何发送消息或某种通知 节点JS: server.on('connection', function(client) { client.on('stream', function (stream, meta) { stream.on('end', function
.Stream.end()
函数后,从服务器上获得一个回调事件
我似乎不明白-当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
});
});
});
client = new BinaryClient(nodeURL);
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
// <--- I want to recieve the callback message
server.on('connection', function(client) {
client.on('stream', function (stream, meta) {
stream.on('end', function () {
fileWriter.end();
client.send('finished');
});
});
});
client = new BinaryClient(nodeURL);
client.on('stream', data => {
console.log(data); // do something with data
});
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
server.on('connection',函数(客户端){
client.on('stream',函数(stream,meta){
stream.on('end',function(){
fileWriter.end();
//在服务器端,您可以使用.send
向客户端发送流。您可以发送各种数据类型,但在这种情况下,一个简单的字符串可能就足够了
在客户端,您还可以监听'stream'
事件以从服务器接收数据
节点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
});
});
});
client = new BinaryClient(nodeURL);
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
// <--- I want to recieve the callback message
server.on('connection', function(client) {
client.on('stream', function (stream, meta) {
stream.on('end', function () {
fileWriter.end();
client.send('finished');
});
});
});
client = new BinaryClient(nodeURL);
client.on('stream', data => {
console.log(data); // do something with data
});
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
客户端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
});
});
});
client = new BinaryClient(nodeURL);
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
// <--- I want to recieve the callback message
server.on('connection', function(client) {
client.on('stream', function (stream, meta) {
stream.on('end', function () {
fileWriter.end();
client.send('finished');
});
});
});
client = new BinaryClient(nodeURL);
client.on('stream', data => {
console.log(data); // do something with data
});
window.Stream = client.createStream({ metaData });
....
window.Stream.end();
在节点JS端,您可以尝试client.send(“finished”)
@ExplosionPills,在客户端我应该做什么?听stream
事件,client.On(“stream”,data=>/*处理数据*)
@ExplosionPills抱歉,我没听懂,你能在客户端和服务器端准确地解释一下代码吗?根据.end()
似乎期望函数作为参数“在调用stream.end
时发出。stream.readable
设置为false。”window.stream.end(function()){//stream end});
我添加了您建议的代码,但是client.on('stream',data=>
从未被触发。