class Druzy::Upnp::Ssdp
Constants
- MEDIA_RENDERER
- MEDIA_SERVER
Public Class Methods
new()
click to toggle source
# File lib/druzy/upnp/ssdp.rb, line 17 def initialize end
Public Instance Methods
search(st = "ssdp:all", delay = 10) { |upnp_device(:location => location)| ... }
click to toggle source
search only device (not service)
# File lib/druzy/upnp/ssdp.rb, line 22 def search(st = "ssdp:all", delay = 10) message = <<-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(message,0,@@host,@@port) devices = [] begin Timeout::timeout(delay) do loop do message = s.recv(4196) location = message.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