Class: WebsocketServer

Inherits:
Object
  • Object
show all
Defined in:
lib/websocket_server.rb

Instance Method Summary collapse

Constructor Details

#initializeWebsocketServer

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.onmessage { |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