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
Under Ruby 1.9, received messages are encoded as US-ASCII #57
Comments
Even worse: ws.onmessage do |msg| ws.send "iñaki" end And it just sends "iñak". And for enxt message it produces an error in the JS side: One or more reserved bits are on: reserved1 = 1, reserved2 = 1, reserved3 = 0 probably due to the remaining byte. |
IMHO the problem is here: https://github.com/igrigorik/em-websocket/blob/master/lib/em-websocket/framing07.rb#L121 length = application_data.size Under Ruby 1.9, "iñaki".size returns 5, but using UTF-8 there are 6 bytes. Use String#bytesize: length = (application_data.respond_to?(:bytesize) ? application_data.bytesize : application_data.size) This solves the issue. |
Thanks for reporting this - responding to each part separately onmessage returns US-ASCII string:
sending non-ascii data caused js error:
|
The problem with the non-ascii data is that (before current fix I hope) the frame size said 10 but the payload size was 11 (for example) due to the usage of String#size (which in Ruby 1.9 should be String#bytesize). So the JS client keeps a buffered byte and when receives a new frame from the server it parses the data incorrectly (obvious as it has a garbage first byte). Anyhow indeed I see the line https://github.com/igrigorik/em-websocket/blob/master/lib/em-websocket/connection.rb#L131 which should fix the issue. However it didn't work for me until I used String#bytesize. Have you tested my example code using Ruby 1.9? ws.onmessage do |msg| ws.send "iñaki" end |
No idea, I cannot reproduce the issue again (I mean the last one using ws.send). |
How frustrating... I'll leave this issue closed for now, but if we see this again we'll reopen. Cheers |
still getting US-ASCII on onmessage ... how can i get UTF-8 ?! |
@refaelos are you using the released version of em-websocket or the code from master? This fix hasn't made it into a released version yet - I will try to get round to that soon. |
how do i use it in my Gemfile ? when i just put "gem 'em-websocket'" i get the code without the fix. |
Just take a look at the bundler docs for including git repos On 9 Hyd 2011, at 16:46, refaelosreply@reply.github.com wrote:
|
10x |
I'm still seeing this issue after upgrading to 0.3.2. Any suggestions? |
@smpallen99 would be great if you could elaborate - as far as I know this should all be fixed. Which ruby version & websocket draft / browser in particular? |
I'm using ruby-1.9.2-p290. I get the following message in chrome: I get the following message in firefox 6.0.2: The strange this is I have two PCs that are almost identical, one has the issue and the other does not. I also have another user that has been using my site for a couple months now, but just started experiencing the problem a couple days ago. |
@smpallen99 so your issue is not related to received message encoding? Could you open a new issue in that case? |
It produces "US-ASCII" even when using Ruby 1.9. It would be much better to produce a UTF-8 string (as WebSocket protocol mandates text messages under UTF-8).
The text was updated successfully, but these errors were encountered: