em-cometio-client
Sinatra CometIO Client for eventmachine
Installation
% gem install em-cometio-client
Usage
require 'eventmachine'
require 'em-cometio-client'
EM::run do
client = EM::CometIO::Client.new('http://localhost:5000/cometio/io').connect
client.timeout = 120 # comet-get timeout
client.on :connect do |session|
puts "connect!! (sessin_id:#{session})"
end
client.on :error do |err|
STDERR.puts err
end
## regist receive "chat" event
client.on :chat do |data|
puts "#{data['name']} - #{data['message']}"
end
## push "chat" event to Server
EM::add_periodic_timer 10 do
client.push :chat, {:message => Time.now.to_s, :name => 'clock'}
end
end
Sample
start chat server
% git clone git://github.com/shokai/cometio-chat-sample.git
% cd cometio-chat-sample
% bundle install
% foreman start
sample chat client
% ruby sample/cui_chat_client.rb
Test
% gem install bundler
% bundle install
start server
% bundle exec rake test_server
test
% bundle exec rake test
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request