lib/cosmos/interfaces/udp_interface.rb in cosmos-3.6.3 vs lib/cosmos/interfaces/udp_interface.rb in cosmos-3.7.0

- old
+ new

@@ -26,18 +26,20 @@ # configure the outgoing multicast address. # @param ttl [Integer] Time To Live value. The number of intermediate # routers allowed before dropping the packet. # @param write_timeout [Integer] Seconds to wait before aborting writes # @param read_timeout [Integer] Seconds to wait before aborting reads + # @param bind_address [String] Address to bind UDP ports to def initialize(hostname, write_dest_port, read_port, write_src_port = nil, interface_address = nil, ttl = 128, # default for Windows write_timeout = 10.0, - read_timeout = nil) + read_timeout = nil, + bind_address = "0.0.0.0") super() @hostname = ConfigParser.handle_nil(hostname) if @hostname @hostname = @hostname.to_s @@ -55,10 +57,12 @@ @ttl = 1 if @ttl < 1 @write_timeout = ConfigParser.handle_nil(write_timeout) @write_timeout = @write_timeout.to_f if @write_timeout @read_timeout = ConfigParser.handle_nil(read_timeout) @read_timeout = @read_timeout.to_f if @read_timeout + @bind_address = ConfigParser.handle_nil(interface_address) + @bind_address = '127.0.0.1' if @bind_address and @bind_address.upcase == 'LOCALHOST' @write_socket = nil @read_socket = nil @read_allowed = false unless @read_port @write_allowed = false unless @write_dest_port @write_raw_allowed = false unless @write_dest_port @@ -70,11 +74,12 @@ def connect @write_socket = UdpWriteSocket.new(@hostname, @write_dest_port, @write_src_port, @interface_address, - @ttl) if @write_dest_port - @read_socket = UdpReadSocket.new(@read_port,@hostname,@interface_address) if @read_port + @ttl, + @bind_address) if @write_dest_port + @read_socket = UdpReadSocket.new(@read_port, @hostname, @interface_address, @bind_address) if @read_port end # @return [Boolean] Whether the active ports (read and/or write) have # created sockets. Since UDP is connectionless, creation of the sockets # is used to determine connection.