Created
November 24, 2011 15:42
-
-
Save ql/1391637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| it "should process close on message correctly " do | |
| EventMachine.run { | |
| MSG = "hello bi-directional data exchange" | |
| EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8085, :debug => true) do |ws| | |
| ws.onopen { p [:OPENED_WS, ws]} | |
| ws.onmessage {|msg| ws.close_webscoket } | |
| ws.onerror {|e| p [:WS_ERROR, e]} | |
| ws.onclose { p [:WS_CLOSE, ws]} | |
| end | |
| http = EventMachine::WebsocketRequest.new('ws://127.0.0.1:8085/').get :keepalive => true | |
| http.errback { failed(http) } | |
| http.callback { | |
| http.response_header.status.should == 101 | |
| http.response_header['CONNECTION'].should match(/Upgrade/) | |
| http.response_header['UPGRADE'].should match(/websocket/) | |
| # push should only be invoked after handshake is complete | |
| http.send(MSG) | |
| } | |
| http.stream { |chunk| | |
| chunk.should == MSG | |
| EventMachine.stop | |
| } | |
| } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment