-
Notifications
You must be signed in to change notification settings - Fork 3
EM::RocketIO::Client
shokai edited this page Mar 24, 2013
·
2 revisions
RocketIO Ruby client for EventMachine
% gem install em-rocketio-client
require 'eventmachine'
require 'em-rocketio-client'
EM::run do
io = EM::RocketIO::Client.new('http://localhost:5000').connect
io.on :connect do |session|
puts "#{io.type} connect!! (sessin_id:#{session})"
end
io.on :disconnect do
puts "#{io.type} disconnect"
end
io.on :error do |err|
STDERR.puts err
end
## regist receive "chat" event
io.on :chat do |data|
puts "#{data['name']} - #{data['message']}"
end
## push "chat" event to Server
io.once :connect do
EM::add_periodic_timer 10 do
io.push :chat, {:message => Time.now.to_s, :name => 'clock'}
end
end
end
io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
io = EM::RocketIO::Client.new('http://localhost:5000', :type => :websocket).connect