给出以下示例:
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/