Sha256: 29e4cfab3661603b8d21941dd2db2eceaa81d3b3bbd80d1dd1159a75019e94d8

Contents?: true

Size: 831 Bytes

Versions: 3

Compression:

Stored size: 831 Bytes

Contents

#!/usr/bin/env ruby
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'rubygems'
require 'em-rocketio-client'

name = `whoami`.strip || 'shokai'
url = ARGV.shift || 'http://localhost:5000'
type = ARGV.shift || :websocket

EM::run do
  io = EM::RocketIO::Client.new(url, :type => type).connect
  # io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).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 :chat do |data|
    puts "<#{data['name']}> #{data['message']}"
  end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
em-rocketio-client-0.1.2 sample/cui_chat_client.rb
em-rocketio-client-0.1.1 sample/cui_chat_client.rb
em-rocketio-client-0.1.0 sample/cui_chat_client.rb