BinaryJS服务器响应

时间:2015-09-21 11:11:27

标签: 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来做这件事,但我不明白怎么做。

1 个答案:

答案 0 :(得分:2)

服务器端:

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);
    });
}

);