Class: WebsocketServer
- Inherits:
-
Object
- Object
- WebsocketServer
- Defined in:
- lib/websocket_server.rb
Instance Method Summary collapse
-
#initialize ⇒ WebsocketServer
constructor
A new instance of WebsocketServer.
- #send(mess) ⇒ Object
Constructor Details
#initialize ⇒ WebsocketServer
Returns a new instance of WebsocketServer.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/websocket_server.rb', line 5 def initialize @connected = [] a = Thread.start do EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws| ws.onopen { @connected << ws } ws. { |msg| } ws.onclose { @connected.delete(ws) } end end end |
Instance Method Details
#send(mess) ⇒ Object
22 23 24 25 26 |
# File 'lib/websocket_server.rb', line 22 def send(mess) @connected.each do |c| c.send mess end end |