rf-web/vendor/bundle/gems/em-websocket-0.5.1/examples/echo.rb

25 lines
545 B
Ruby
Raw Normal View History

2019-10-21 08:18:17 +00:00
require File.expand_path('../../lib/em-websocket', __FILE__)
EM.run {
EM::WebSocket.run(:host => "0.0.0.0", :port => 8080, :debug => false) do |ws|
ws.onopen { |handshake|
puts "WebSocket opened #{{
:path => handshake.path,
:query => handshake.query,
:origin => handshake.origin,
}}"
ws.send "Hello Client!"
}
ws.onmessage { |msg|
ws.send "Pong: #{msg}"
}
ws.onclose {
puts "WebSocket closed"
}
ws.onerror { |e|
puts "Error: #{e.message}"
}
end
}