Class: Netz::Catcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCatcher

Returns a new instance of Catcher.



5
6
7
# File 'lib/netz/catcher.rb', line 5

def initialize()
  @remote_clients = []
end

Instance Attribute Details

#command_channelObject

Returns the value of attribute command_channel.



3
4
5
# File 'lib/netz/catcher.rb', line 3

def command_channel
  @command_channel
end

#remote_clientsObject

Returns the value of attribute remote_clients.



3
4
5
# File 'lib/netz/catcher.rb', line 3

def remote_clients
  @remote_clients
end

Instance Method Details

#read_command(remote_client) ⇒ Object



20
21
22
23
24
# File 'lib/netz/catcher.rb', line 20

def read_command(remote_client)
  length = remote_client.recvfrom(2)[0].unpack("S")[0]
  cmd = CommandSerializer.deserialize(remote_client.recvfrom(length))
  @command_channel << cmd 
end

#runObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/netz/catcher.rb', line 9

def run
  #thread per client?
  @remote_clients.each do |rc|
    Thread.new do
      loop do
        read_command(rc)
      end
    end
  end
end