-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encode stream does not proactively send data to its output #80
Comments
Example: const msgpack = require("msgpack-lite")
const net = require('net')
net.createServer(socket => {
const encodeStream = msgpack.createEncodeStream()
encodeStream.pipe(socket)
// Send 'hi' to the socket every second
setInterval(() => encodeStream.write('hi'), 1000)
}).listen(3300)
console.log('TCP server listening on port 3300') This server should send a msgpack message containing 'hi' to each client every second. Instead the stream internally buffers the small messages and nothing gets sent to the network socket. $ nc localhost 3300
# No output!? The problem is avoided by calling |
I bumped into this issue as well, as a workaround I'm calling Would extending
This would make |
Yeah that'd do the trick! |
Right.
Using it with I rather use the simple |
@kawanet WebSocket is message-oriented, so const echo = (value, enc) => {
enc.write(value)
enc._flush() // required, otherwise client won't get the the response
}
net.createServer(socket => {
const enc = msgpack.createEncodeStream()
const dec = msgpack.createDecodeStream()
enc.pipe(socket)
socket.pipe(dec)
dec.on('data', value => echo(value, enc))
}).listen(3300) |
If you create an encode stream and pipe it somewhere (for example, the network), the data you send to the stream won't be forwarded automatically. It only seems to be sent when the server
end()
's the writable stream. This makes the transform stream basically unusable for streaming realtime data.There's a workaround of calling
stream.encoder.flush()
, but that seems brittle.The text was updated successfully, but these errors were encountered: