Class: RUPNP::SSDP::Searcher
- Inherits:
-
MulticastConnection
- Object
- EM::Connection
- MulticastConnection
- RUPNP::SSDP::Searcher
- Includes:
- HTTP
- Defined in:
- lib/rupnp/ssdp/searcher.rb
Overview
Searcher class for searching devices
Constant Summary collapse
- DEFAULT_M_SEARCH_TRY =
Number of SEARCH datagrams to send
2
Constants included from LogMixin
Instance Attribute Summary collapse
-
#discovery_responses ⇒ EM::Channel
readonly
Channel to receive discovery responses.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Searcher
constructor
A new instance of Searcher.
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
Methods included from HTTP
#get_http_headers, #get_http_verb, #is_http_status_ok?
Methods inherited from MulticastConnection
Methods included from LogMixin
Constructor Details
#initialize(options = {}) ⇒ Searcher
Returns a new instance of Searcher.
22 23 24 25 26 27 28 |
# File 'lib/rupnp/ssdp/searcher.rb', line 22 def initialize(={}) @options = @options[:try_number] ||= DEFAULT_M_SEARCH_TRY @discovery_responses = EM::Channel.new super [:ttl] end |
Instance Attribute Details
#discovery_responses ⇒ EM::Channel (readonly)
Channel to receive discovery responses
14 15 16 |
# File 'lib/rupnp/ssdp/searcher.rb', line 14 def discovery_responses @discovery_responses end |
Instance Method Details
#post_init ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rupnp/ssdp/searcher.rb', line 31 def post_init search = search_request @options[:try_number].times do send_datagram search, MULTICAST_IP, DISCOVERY_PORT log :debug, "send datagram:\n#{search}" end end |
#receive_data(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rupnp/ssdp/searcher.rb', line 40 def receive_data(data) port, ip = peer_info log :debug, "Response from #{ip}:#{port}:" log :debug, data response = StringIO.new(data) if !is_http_status_ok?(response) log :error, "bad HTTP response:\n #{data}" return end @discovery_responses << get_http_headers(response) end |