Class: SimpleUpnp::Discovery

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_upnp/discovery.rb

Constant Summary collapse

SSDP_ADDR =
'239.255.255.250'
SSDP_PORT =
1900
M_SEARCH =
"M-SEARCH * HTTP/1.1\r\nHOST: #{SSDP_ADDR}:#{SSDP_PORT}\r\nMAN: \"ssdp:discover\"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n"
MAX_RECEIVE_LENGTH =
65536

Class Method Summary collapse

Class Method Details

.find(seconds_to_listen = 5, &block) ⇒ Object

Signal the uPnP Multicast address and wait for responses, which can be processed by an input block accepting a SimpleUpnp::Device Use break to exit the block once you have found the device being looked for



27
28
29
30
31
32
33
34
# File 'lib/simple_upnp/discovery.rb', line 27

def self.find(seconds_to_listen=5, &block)
  open_socket do |socket|
    process_messages(socket, seconds_to_listen) do |message|
      device = SimpleUpnp::Device.new(message)
      yield device
    end
  end
end

.search(seconds_to_listen = 5) ⇒ Object

Signal the uPnP Multicast address and wait for responses, returning an array of SimpleUpnp::Devices



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simple_upnp/discovery.rb', line 13

def self.search(seconds_to_listen=5)
  devices = []
  open_socket do |socket|
    process_messages(socket, seconds_to_listen) do |message|
      device = SimpleUpnp::Device.new(message)
      index = devices.index { |x| x.usn == device.usn }
      devices << device if index.nil?
    end
  end
  devices
end