Module: WSDiscovery
- Includes:
- NetworkConstants
- Defined in:
- lib/ws_discovery.rb,
lib/ws_discovery/error.rb,
lib/ws_discovery/version.rb,
lib/ws_discovery/response.rb,
lib/ws_discovery/network_constants.rb,
lib/ws_discovery/multicast_connection.rb
Defined Under Namespace
Modules: NetworkConstants Classes: Error, MulticastConnection, Response, Searcher
Constant Summary collapse
- DEFAULT_WAIT_TIME =
5
- VERSION =
'0.0.2'
Constants included from NetworkConstants
NetworkConstants::MULTICAST_IP, NetworkConstants::MULTICAST_PORT, NetworkConstants::TTL
Class Method Summary collapse
-
.search(options = {}) ⇒ Array<WSDiscovery::Response>, WSDiscovery::Searcher
Opens a UDP socket on 0.0.0.0, on an ephemeral port, has WSDiscovery::Searcher build and send the search request, then receives the responses.
Class Method Details
.search(options = {}) ⇒ Array<WSDiscovery::Response>, WSDiscovery::Searcher
Opens a UDP socket on 0.0.0.0, on an ephemeral port, has WSDiscovery::Searcher build and send the search request, then receives the responses. The search will stop after response_wait_time
.
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 |
# File 'lib/ws_discovery.rb', line 27 def self.search(={}) response_wait_time = [:response_wait_time] || DEFAULT_WAIT_TIME responses = [] multicast_searcher = proc do EM.open_datagram_socket('0.0.0.0', 0, WSDiscovery::Searcher, ) end if EM.reactor_running? return multicast_searcher.call else EM.run do ms = multicast_searcher.call ms.discovery_responses.subscribe do |notification| responses << notification end EM.add_timer(response_wait_time) { EM.stop } trap_signals end end responses.flatten end |