Class: Whistle::Relay

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

Class Method Summary collapse

Class Method Details

.activateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/relay.rb', line 5

def self.activate
  Thread.new do
    server = TCPServer.new($config.relay.host, $config.relay.port)
    puts "Started relay on port #{$config.relay.port}"
    while s = server.accept
      begin
        msg = s.gets
        puts "Received #{msg}, relaying"
        msg.chomp!.strip! unless msg.blank?
        $switchbox.deliver(msg) unless msg.blank?
      rescue => e
        puts "ERROR: #{e.message}"
      ensure
        s.close
      end
    end
  end #.abort_on_exception = true
end