Skip to content

Sinatra::RocketIO::Client

Sho Hashimoto edited this page Jun 5, 2013 · 6 revisions

sinatra-rocketio gem has Ruby client library.

#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra/rocketio/client'

io = Sinatra::RocketIO::Client.new('http://localhost:5000').connect

io.on :connect do |session|
  puts "#{io.type} connect!! (session_id:#{session})"
end

io.on :chat do |data|
  puts "<#{data['name']}> #{data['message']}"
end

io.on :error do |err|
  STDERR.puts err
end

io.on :disconnect do
  puts "disconnected!!"
end

loop do
  line = STDIN.gets.strip
  next if line.empty?
  io.push :chat, {:message => line, :name => name}
end

connection type

io = Sinatra::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
io = Sinatra::RocketIO::Client.new('http://localhost:5000', :type => :websocket).connect

sample

Clone this wiki locally