forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 2
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
implement sending a message for WS and add a websocketFrame class #30
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that there is no guarantee that
chunk
is a complete frame. It might be just the first few bytes of a frame, a slice in the middle of a frame, the tail of frame and the beginning of another, or multiple frames.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lpinca, Thank you for your feedback. I was under the impression that any websocket server will flush the socket buffer after each complete frame and we'll always get a chunk with a full frame.
Do you know an easy way to spin up a ws server where I can test these cases?
1- buffer with incomplete frame
2- buffer with multiple frames
3. etc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is outside of the control of any server. It depends on the OS, the protocol (TCP), the network, etc. When you call
socket.write(data)
, there is no guarantee that the other peer receives all the data as a single TCP packet.It is easier to do it without a real server. Take a look at https://github.com/websockets/ws/blob/8.11.0/lib/receiver.js and https://github.com/websockets/ws/blob/8.11.0/test/receiver.test.js.
Keep also in mind that the WHATWG spec advertises support for the
permessage-deflate
extension, so if the server you are connecting to also supportspermessage-deflate
, you might receive frames whose payload data is compressed. If decompression is slower than incoming data, you also have to handle backpressure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lpinca