Class: Netz::Catcher
- Inherits:
-
Object
- Object
- Netz::Catcher
- Defined in:
- lib/netz/catcher.rb
Instance Attribute Summary collapse
-
#command_channel ⇒ Object
Returns the value of attribute command_channel.
-
#remote_clients ⇒ Object
Returns the value of attribute remote_clients.
Instance Method Summary collapse
-
#initialize ⇒ Catcher
constructor
A new instance of Catcher.
- #read_command(remote_client) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Catcher
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_channel ⇒ Object
Returns the value of attribute command_channel.
3 4 5 |
# File 'lib/netz/catcher.rb', line 3 def command_channel @command_channel end |
#remote_clients ⇒ Object
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 |
#run ⇒ Object
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 |