-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsample.rb
More file actions
35 lines (27 loc) · 678 Bytes
/
sample.rb
File metadata and controls
35 lines (27 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'rubygems'
require 'socket.io-client-simple'
url = ARGV.shift || 'http://localhost:3000'
socket = SocketIO::Client::Simple.connect url
# socket.auto_reconnection = false
#socket.websocket.on :message do |msg| ## inspect websocket data
# p msg.data
#end
socket.on :connect do
puts "connect!!!"
end
socket.on :disconnect do
puts "disconnected!!"
end
socket.on :chat do |data|
puts "> " + data['msg']
end
socket.on :error do |err|
p err
end
puts "please input and press Enter key"
loop do
msg = STDIN.gets.strip
next if msg.empty?
socket.emit :chat, {:msg => msg, :at => Time.now}
end