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

em-websocketio-client

Sinatra WebSocketIO Client for eventmachine

Installation

% gem install em-websocketio-client

Usage

require 'eventmachine'
require 'em-websocketio-client'

EM::run do
  client = EM::WebSocketIO::Client.new('ws://localhost:9000').connect

  client.on :connect do |session|
    puts "connect!! (sessin_id:#{session})"
  end

  client.on :disconnect do
    puts "disconnect websocketio"
  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/websocketio-chat-sample.git
% cd websocketio-chat-sample
% bundle install
% foreman start

=> http://localhost:5000

sample chat client

% ruby sample/cui_chat_client.rb

Test

% gem install bundler
% bundle install

start test server

% bundle exec rake test_server

run test

% bundle exec 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