Skip to content

Instantly share code, notes, and snippets.

@knewter
Created April 24, 2013 22:14
Show Gist options
  • Save knewter/5456058 to your computer and use it in GitHub Desktop.
Save knewter/5456058 to your computer and use it in GitHub Desktop.
websocket mtgox celluloid example
require 'celluloid/websocket/client'
class MozWeb
include Celluloid
include Celluloid::Logger
def initialize
@client = Celluloid::WebSocket::Client.new("ws://websocket.mtgox.com/mtgox?Currency=USD", current_actor)
@counter = 0
end
def on_open
debug("websocket connection opened")
end
def on_message(data)
@counter += 1
info("message: #{data.inspect}")
@client.close if @counter > 5
end
def on_close(code, reason)
debug("websocket connection closed: #{code.inspect}, #{reason.inspect}")
end
end
MozWeb.new
sleep
--(jadams@aye-seven)-(62/pts/3)-(1717/24-Apr-13)--
--($:~/ruby/celluloid-websocket-client)(master)ruby-1.9.3-p374@celluloid-websocket-client--
$ bundle exec ruby examples/client.rb
E, [2013-04-24T17:17:48.141427 #28759] ERROR -- : Celluloid::WebSocket::Client::Connection crashed!
EOFError: end of file reached
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-io-646c1d701428/lib/celluloid/io/stream.rb:44:in `block in sysread'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-io-646c1d701428/lib/celluloid/io/stream.rb:399:in `synchronize'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-io-646c1d701428/lib/celluloid/io/stream.rb:42:in `sysread'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-io-646c1d701428/lib/celluloid/io/stream.rb:128:in `readpartial'
/home/jadams/ruby/celluloid-websocket-client/lib/celluloid/websocket/client/connection.rb:36:in `block in run'
/home/jadams/ruby/celluloid-websocket-client/lib/celluloid/websocket/client/connection.rb:35:in `loop'
/home/jadams/ruby/celluloid-websocket-client/lib/celluloid/websocket/client/connection.rb:35:in `run'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/calls.rb:25:in `public_send'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/calls.rb:25:in `dispatch'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/calls.rb:125:in `dispatch'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/actor.rb:328:in `block in handle_message'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/tasks.rb:42:in `block in initialize'
/home/jadams/.rvm/gems/ruby-1.9.3-p374@celluloid-websocket-client/bundler/gems/celluloid-cdfab73bdb7d/lib/celluloid/tasks/task_fiber.rb:9:in `block in create'
D, [2013-04-24T17:17:48.141731 #28759] DEBUG -- : websocket connection closed: 1002, ""
^CD, [2013-04-24T17:17:50.758938 #28759] DEBUG -- : Terminating 1 actors...
D, [2013-04-24T17:17:50.759329 #28759] DEBUG -- : Shutdown completed cleanly
examples/client.rb:30:in `sleep': Interrupt
from examples/client.rb:30:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment