Class: Lorraine::Server

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

Class Method Summary collapse

Class Method Details

.start(port) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lorraine/server.rb', line 8

def self.start(port)
  serial_connection = Lorraine::Connection.new      
  Thin::Server.start('0.0.0.0', port) do
    Faye::WebSocket.load_adapter('thin')
    faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
    faye_server.bind(:publish) do |client_id, channel, data|
      # Process incoming things
      m = Lorraine::Message.from_packet(data)
      puts "Received message: #{m}"
      serial_connection.write_message(m)
    end
    run faye_server
  end
end