No commit activity in last 3 years
No release in over 3 years
Sinatra RocketIO client for eventmachine
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Project Readme

em-rocketio-client

Sinatra RocketIO Client for eventmachine

Installation

% gem install em-rocketio-client

Usage

require 'eventmachine'
require 'em-rocketio-client'

EM::run do
  io = EM::RocketIO::Client.new('http://localhost:5000').connect
  # io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
  # io = EM::RocketIO::Client.new('http://localhost:5000', :channel => '1').connect
  io.on :connect do
    puts "#{io.type} connect!! (sessin_id:#{io.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
  EM::add_periodic_timer 10 do
    io.push :chat, {:message => Time.now.to_s, :name => 'clock'}
  end
end

Sample

start chat server

% git clone git://github.com/shokai/sinatra-rocketio.git
% cd sinatra-rocketio
% bundle install
% cd sample/classic_style
% rackup config.ru -p 5000

=> http://localhost:5000

sample chat client

% ruby sample/cui_chat_client.rb
% ruby sample/cui_chat_client.rb http://localhost:5000 comet
% ruby sample/cui_chat_client.rb http://localhost:5000 websocket

Test

% gem install bundler
% bundle install

start server

% export PORT=5000
% export WS_PORT=9000
% rake test_server

run test

% rake test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request