Method: Cosmos::UdpInterface#initialize

Defined in:
lib/cosmos/interfaces/udp_interface.rb

#initialize(hostname, write_dest_port, read_port, write_src_port = nil, interface_address = nil, ttl = 128, write_timeout = 10.0, read_timeout = nil, bind_address = '0.0.0.0') ⇒ UdpInterface

Returns a new instance of UdpInterface.

Parameters:

  • hostname (String)

    Machine to connect to

  • write_dest_port (Integer)

    Port to write commands to

  • read_port (Integer)

    Port to read telemetry from

  • write_src_port (Integer) (defaults to: nil)

    Port to allow replies if needed

  • interface_address (String) (defaults to: nil)

    If the destination machine represented by hostname supports multicast, then interface_address is used to configure the outgoing multicast address.

  • ttl (Integer) (defaults to: 128)

    Time To Live value. The number of intermediate routers allowed before dropping the packet.

  • write_timeout (Integer) (defaults to: 10.0)

    Seconds to wait before aborting writes

  • read_timeout (Integer) (defaults to: nil)

    Seconds to wait before aborting reads

  • bind_address (String) (defaults to: '0.0.0.0')

    Address to bind UDP ports to



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cosmos/interfaces/udp_interface.rb', line 39

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,
  bind_address = '0.0.0.0'
)

  super()
  @hostname = ConfigParser.handle_nil(hostname)
  if @hostname
    @hostname = @hostname.to_s
    @hostname = '127.0.0.1' if @hostname.casecmp('LOCALHOST').zero?
  end
  @write_dest_port = ConfigParser.handle_nil(write_dest_port)
  @write_dest_port = write_dest_port.to_i if @write_dest_port
  @read_port = ConfigParser.handle_nil(read_port)
  @read_port = read_port.to_i if @read_port
  @write_src_port = ConfigParser.handle_nil(write_src_port)
  @write_src_port = @write_src_port.to_i if @write_src_port
  @interface_address = ConfigParser.handle_nil(interface_address)
  if @interface_address && @interface_address.casecmp('LOCALHOST').zero?
    @interface_address = '127.0.0.1'
  end
  @ttl = ttl.to_i
  @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(bind_address)
  if @bind_address && @bind_address.casecmp('LOCALHOST').zero?
    @bind_address = '127.0.0.1'
  end
  @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
end