Class: Druzy::Upnp::Ssdp
- Inherits:
-
Object
- Object
- Druzy::Upnp::Ssdp
- Defined in:
- lib/druzy/upnp/ssdp.rb
Constant Summary collapse
- @@port =
1900
- @@host =
"239.255.255.250"
Instance Method Summary collapse
-
#initialize ⇒ Ssdp
constructor
A new instance of Ssdp.
-
#search(st = "ssdp:all", delay = 10) ⇒ Object
search only device (not service).
Constructor Details
#initialize ⇒ Ssdp
Returns a new instance of Ssdp.
14 15 16 |
# File 'lib/druzy/upnp/ssdp.rb', line 14 def initialize end |
Instance Method Details
#search(st = "ssdp:all", delay = 10) ⇒ Object
search only device (not service)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/druzy/upnp/ssdp.rb', line 19 def search(st = "ssdp:all", delay = 10) = <<-MESSAGE M-SEARCH * HTTP/1.1\r HOST: #{@@host}:#{@@port}\r MAN: "ssdp:discover"\r MX: #{delay}\r ST: #{st}\r USER-AGENT: #{RbConfig::CONFIG["host_os"]}/ UPnP/1.1 ruby-druzy-upnp/#{Druzy::Upnp::VERSION}\r MESSAGE s = UDPSocket.new s.send(,0,@@host,@@port) devices = [] begin Timeout::timeout(delay) do loop do = s.recv(4196) location = .split("\n").reject{|line| line==nil || line["LOCATION"]==nil}.first location = location[location.index(" ")+1..location.size-2] if !devices.include?(location) devices << location if block_given? yield UpnpDevice.new(:location => location) end end end end rescue ensure s.close end end |