Skip to content
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

WebSocket: Add support for receiving binary messages #2774

Merged
merged 1 commit into from
Apr 11, 2017

Conversation

lbguilherme
Copy link
Contributor

This is not an ideal implementation, it would be better if the on_binary block received some kind of IO that could be read while each part of the binary message arrives instead. I'll do that at a later moment. Either way, this is at least working.

@@ -73,6 +76,12 @@ class HTTP::WebSocket
@on_message.try &.call(@current_message.to_s)
@current_message.clear
end
when Protocol::Opcode::BINARY
@current_message.write @buffer[0, info.size]
Copy link
Member

@jhass jhass Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know nothing about the websocket protocol, so excuse me in case it's obvious. So binary message are too at maximum 4096 bytes big?

Er, nvm, I shouldn't look at stuff anymore today.

@jhass
Copy link
Member

jhass commented Jun 10, 2016

I know there are no existing specs for this area of the code, would you mind looking into adding one for this nonetheless? Otherwise LGTM.

@@ -40,6 +40,9 @@ class HTTP::WebSocket
def on_message(&@on_message : String ->)
end

def on_binary(&@on_binary : Slice(UInt8) ->)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slice(UInt8) -> Bytes

@asterite
Copy link
Member

Let's merge this, if there are things to improve we can do it later

@asterite asterite merged commit 0d4c040 into crystal-lang:master Apr 11, 2017
@asterite asterite added this to the Next milestone Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants