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
|
# File 'lib/cloud_powers/synapse/websocket/websocclient.rb', line 7
def create_websoc_client( host, port )
EM.run do
ws = WebSocket::EventMachine::Client.connect(:uri => 'ws://' + host + ':' + port)
ws.onopen do
puts "Connected"
end
ws.onmessage do |msg, type|
puts "Received message: #{msg}"
end
ws.onerror do |error|
puts "Error ==> #{error}"
end
ws.onclose do |code, reason|
puts "Disconnected with status code: #{code}"
puts "Disconnected with status message: #{reason}"
end
EventMachine.next_tick do
ws.send "Hello Server!"
end
end
end
|