Class: Wires::Cluster::UDP::Xceiver
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#local_ip ⇒ Object
readonly
Returns the value of attribute local_ip.
-
#local_port ⇒ Object
readonly
Returns the value of attribute local_port.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(group, port, **kwargs) ⇒ Xceiver
constructor
A new instance of Xceiver.
- #open ⇒ Object
Constructor Details
#initialize(group, port, **kwargs) ⇒ Xceiver
Returns a new instance of Xceiver.
22 23 24 25 26 27 |
# File 'lib/wires/cluster/udp.rb', line 22 def initialize(group, port, **kwargs) @group = group @port = port kwargs.each_pair { |k,v| instance_variable_set("@#{k}".to_sym, v) } open end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
13 14 15 |
# File 'lib/wires/cluster/udp.rb', line 13 def group @group end |
#local_ip ⇒ Object (readonly)
Returns the value of attribute local_ip.
13 14 15 |
# File 'lib/wires/cluster/udp.rb', line 13 def local_ip @local_ip end |
#local_port ⇒ Object (readonly)
Returns the value of attribute local_port.
13 14 15 |
# File 'lib/wires/cluster/udp.rb', line 13 def local_port @local_port end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/wires/cluster/udp.rb', line 13 def port @port end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
13 14 15 |
# File 'lib/wires/cluster/udp.rb', line 13 def socket @socket end |
Class Method Details
.new(*args) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/wires/cluster/udp.rb', line 15 def self.new(*args) if (self.class==Xceiver) raise TypeError, "#{self.class} is an 'abstract class' only."\ " Inherit it; don't instantiate it!"; end super end |
Instance Method Details
#close ⇒ Object
40 41 42 43 |
# File 'lib/wires/cluster/udp.rb', line 40 def close @socket.close if @socket @socket = nil end |
#open ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wires/cluster/udp.rb', line 29 def open @socket.close if @socket @socket = UDPSocket.new configure @local_ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?} @local_port = @socket.addr[1] return @socket ensure @finalizer ||= ObjectSpace.define_finalizer self, Proc.new { close } end |