Created
July 13, 2010 01:55
-
-
Save frsyuki/473344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rev/websocket' | |
$connections = [] | |
class MyConnection < Rev::WebSocket | |
def on_open | |
puts "WebSocket opened" | |
$connections << self | |
end | |
def on_message(data) | |
puts "WebSocket data received: '#{data}'" | |
# broadcast | |
$connections.each do |c| | |
c.send_message data | |
end | |
end | |
def on_close | |
puts "WebSocket closed" | |
$connections.delete(self) | |
end | |
end | |
host = '0.0.0.0' | |
port = ARGV[0] || 8080 | |
server = Rev::WebSocketServer.new(host, port, MyConnection) | |
server.attach(Rev::Loop.default) | |
puts "start on #{host}:#{port}" | |
Rev::Loop.default.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment