Class: Radiowaves::Server
- Inherits:
-
Object
- Object
- Radiowaves::Server
- Includes:
- Logging
- Defined in:
- lib/radiowaves/server.rb
Instance Method Summary collapse
-
#initialize(host, port) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
Methods included from Logging
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
8 9 10 11 |
# File 'lib/radiowaves/server.rb', line 8 def initialize(host, port) @host = host @port = port end |
Instance Method Details
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/radiowaves/server.rb', line 13 def start EventMachine.run { @channel = EM::Channel.new EventMachine::WebSocket.start(:host => @host, :port => @port) do |ws| ws.onopen { logger.debug "*** ws.onopen" sid = @channel.subscribe { |msg| ws.send msg } ws. { |msg| @channel.push "#{msg}" } ws.onclose { logger.debug "*** ws.onclose: #{sid}" @channel.unsubscribe(sid) } } end } end |