Comments (26)
The reason why we switched to this was because on tcp and ssl sockets is significantly better to avoid copying the buffers. That slows things down significantly. Ideally the .cork() and writev implementation in Node and ws should take care of chunking and avoiding the problem. There might be something to fix in websocket-stream.
from mqtt-packet.
@mcollina, so if I want to send packet per frame from browser, I must to implement cork() in websocket-stream. Right?
from mqtt-packet.
I think it should be https://github.com/maxogden/websocket-stream/blob/master/stream.js#L154-L166.
Why is this not working?
from mqtt-packet.
@mcollina, as I see, writev turned on by options objectMode is false, but objectMode value by default is false. So, by default I getting packet per frame, but that's not realy. I'm getting all properties of packet per frame separatly. I see it on my broker.
from mqtt-packet.
we should create it in not in object mode in MQTT.js.
from mqtt-packet.
What do you mean? We must to implement it in ws connector in mqtt.js? But how?
from mqtt-packet.
In MQTT.js we need to make sure that the websocket stream is not in object mode
from mqtt-packet.
So, if I added property objectMode: false to wsOptions in my connection, I`m getting set up writev handler in websocket-stream. Then in mqtt-packet in generate function stream's try cork(). But writable stream which's piped with writable stream in mqtt.js can't make writev. As I see, I must to imlement writev in _setupStream and to process objectMode for creating writable stream inside that handler. Right?
from mqtt-packet.
What do you mean with "mqtt.js can't make writev".
from mqtt-packet.
What I mean is:
- the writable stream (in websocket-stream) is piped with the writable stream in mqtt.js
- the latter stream (in mqtt.js) can't peform writev
from mqtt-packet.
Which Writable? This https://github.com/mqttjs/MQTT.js/blob/master/lib/client.js#L245 is used when reading the packets, not when writing them.
from mqtt-packet.
Oh, I see. But I realy can't understand what can I do for to implement sending packet per message. Can you to explain to me, please?
from mqtt-packet.
I do not know where they get chunked up, and where cork() is failing us. https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76 might likely be the issue.
from mqtt-packet.
https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76 probably you are right. Because I'm debugging my app and I see in mqtt-packet stream is Duplexify, but debug way creating Transform stream. And in Duplexify stream objectMode setted in true.
from mqtt-packet.
I think the fix should come to WebSocket stream.
from mqtt-packet.
You are right. Issue in that place. I remove part of logic with duplexify stream, and I get working cork logic..
from mqtt-packet.
@mcollina, do you know the maintainer of websocket-stream package? He is streel alive?) He don`t have activity on github from october 2018..
from mqtt-packet.
from mqtt-packet.
That's great! Can you spell me: cork/uncork part of logic broken in https://github.com/maxogden/websocket-stream/blob/master/stream.js#L76. When I remove that initial stream by duplexify and leave stream = proxy only, everything works well. Can you tell me why you are doing stream by duplexify and what benefits it gives.
from mqtt-packet.
It is used to handle the delayed open scenario. We can remove it, but we might have to change some other things, as we canβt write until the ws is open.
from mqtt-packet.
Duplexify method obj() set objectMode setting in true automaticaly. And if I extending obj() logic with options parameter, it setup objectMode truely, but don't working anyway. Maybe some issue in duplexify too?
from mqtt-packet.
You might have to add our _writev implementation to the duplexify stream as well.
from mqtt-packet.
That's right, but if I added _writev implementation to duplexify, I'm getting packets separated on 2 chunks. (first byte in first frame, but all another bytes in second frame) W/o duplexify it's working as well (all bytes in first frame).
from mqtt-packet.
Then we should remove duplexify and handle the connection state separately.
from mqtt-packet.
@mcollina, I tried remove duplexify from dependensies, but a lot of duplexify logic needed in server side. I fix it, but need you review. max-mapper/websocket-stream#147
from mqtt-packet.
@mcollina, and I retested all mqtt.js with that fix - everything ok
from mqtt-packet.
Related Issues (20)
- Current Typescript definitions are difficult to use to read userProperties
- stop validating protocol level in this package HOT 1
- can't comply with MQTT spec requirements about flag validation HOT 1
- Generate 'puback' package can't set 'qos' properties HOT 5
- Buffer is not defined HOT 1
- SUBSCRIBE packet with no payload HOT 3
- Cannot connect to some MQTT server when the connect packet sent in chunk instead of full packet at once HOT 1
- No callback on writeToStream? HOT 5
- Call `stream.destroy(err)` instead of `stream.emit('error', err)` HOT 1
- Cannot specify subscription identifier when sending a SUBSCRIBE packet
- Publish v8.0.0 to NPM
- Are there any usage examples?
- Will mqtt-packet convert date to timestamp?
- numbers.js cache excessive memory usage HOT 2
- Connect packet HOT 1
- Mqtt 5 puback is different from spec HOT 6
- Typescript HOT 4
- Block-scoped declarations (let, const, function, class) not yet supported outside strict mode HOT 3
- Regression in v6.6.0 for parsing multi-byte length header that is split across write calls HOT 5
- Buffer out of bounds when v5 connection request sent to v4 server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt-packet.