node.js - BinaryJS 服务器响应

标签 node.js stream

给出以下示例:

binaryServer = BinaryServer({port: 9001});

binaryServer.on('connection', function(client) {
  console.log("new connection");


  client.on('stream', function(stream, meta) {
    console.log('new stream');
    strean.on('data', function('data'){
    //(code to store audio in buffers)});

    stream.on('end', function() {
      //end of stream
      //(routine that calls an addon and convert speech to text)
      //****Immediate response to client******
    });
  });
});

现在,我的目标是在生成响应后立即发送响应(给客户端)。我正在尝试使用 BinaryJS 来做到这一点但我不明白怎么做。

最佳答案

服务器端:

binaryServer = BinaryServer({port: 9001});

binaryServer.on('connection', function(client) {
  console.log("new connection");


  client.on('stream', function(stream, meta) {
    console.log('new stream');
    strean.on('data', function('data'){
    //(code to store audio in buffers)});

    stream.on('end', function() {
      //end of stream
      //(routine that calls an addon and convert speech to text)
      //****Immediate response to client******
      stream.write(some_variable);<---just do this
    });
  });
});

客户端:

client.on('open', function() {

    Stream = client.createStream("some meta information);
    //(some rotines)
    Stream.on('data', function(data){ ///-->recebe resposta do stream.write()
          console.log("RESULTADO: "+data);
    });
}

);

关于node.js - BinaryJS 服务器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693740/

相关文章:

javascript - 高地在完全消耗之前添加到流中?

java - 从不拥有它的线程解锁锁,或重新设计以避免这种情况?

c# mocking IFormFile CopyToAsync() 方法

javascript - 使用 Node.js 更好地理解回调

node.js - 事件循环作为语言构造公开的其他语言(框架)?

node.js - 快速验证器不产生验证错误

c - fprintf、printf 和 sprintf 之间的区别?

javascript - 如何在另一个函数中模拟一个函数nodejs

javascript - 如何为nodejs和mongodb进行常量和变量混合查询

lambda - 是否可以使用两次 ifPresent,每次检查不同的返回或 fork 映射