Class: Netz::Broadcaster
- Inherits:
-
Object
- Object
- Netz::Broadcaster
- Defined in:
- lib/netz/broadcaster.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 ⇒ Broadcaster
constructor
A new instance of Broadcaster.
- #push_to_peers(command) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Broadcaster
Returns a new instance of Broadcaster.
5 6 7 |
# File 'lib/netz/broadcaster.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/broadcaster.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/broadcaster.rb', line 3 def remote_clients @remote_clients end |
Instance Method Details
#push_to_peers(command) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/netz/broadcaster.rb', line 18 def push_to_peers(command) # TODO add command buffering? command.extend(CommandSerializer) # write to clients msg = command.serialize puts msg @remote_clients.each do |rc| rc.write [msg.length].pack("S") rc.write msg end end |
#run ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/netz/broadcaster.rb', line 9 def run Thread.new do loop do command = @command_channel.pop push_to_peers command if command.local? end end end |