imanel / websocket-ruby

Universal Ruby library to handle WebSocket protocol
447 stars 43 forks source link

example input never get to finished state #10

Closed donpdonp closed 12 years ago

donpdonp commented 12 years ago

I'm trying a clean ruby setup with websockets and the example websocket handshake never gets to finished => true.

The setup

donp@sparky:~/code/tmp$ cat Gemfile
source :rubygems
gem 'websocket'
donp@sparky:~/code/tmp$ bundle install --path gems
Using websocket (1.0.3) 
Using bundler (1.2.1) 
Your bundle is complete! It was installed into ./gems
donp@sparky:~/code/tmp$ ruby -v
ruby 1.9.3p286 (2012-10-12) [i686-linux]

The example

donp@sparky:~/code/tmp$ irb
irb(main):004:0> require 'websocket'
=> true
irb(main):005:0> @handshake = WebSocket::Handshake::Server.new
=> #<WebSocket::Handshake::Server:0x4c68 @state=:new @secure=false @data="" @headers={}>
irb(main):006:0> 
irb(main):007:0* # Parse client request
irb(main):008:0* @handshake << <<EOF
irb(main):009:0" GET /demo HTTP/1.1
irb(main):010:0" Upgrade: websocket
irb(main):011:0" Connection: Upgrade
irb(main):012:0" Host: example.com
irb(main):013:0" Sec-WebSocket-Origin: http://example.com
irb(main):014:0" Sec-WebSocket-Version: 17
irb(main):015:0" Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
irb(main):016:0" 
irb(main):017:0" EOF
=> nil
irb(main):018:0> 
irb(main):019:0* # All data received?
irb(main):020:0* @handshake.finished?
=> false
imanel commented 12 years ago

I've forgot about adding \r at end of lines - HTTP headers should be always divided by \r\n. Just updated readme, together with setting version to 13(all drafts named > 13 have still Sec-WebSocket-Version set to 13). Please check example from readme now and close this issue if it's working.

donpdonp commented 12 years ago

Add \r to the input fixed the problem. thanks!