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

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.

Parameters:

  • options (Hash) (defaults to: {})

    The options for the probe.

Options Hash (options):

  • :env_namespaces (Hash<String>)

    Additional envelope namespaces.

  • :type_attributes (Hash<String>)

    Type attributes.

  • :types (String)

    Types.

  • :scope_attributes (Hash<String>)

    Scope attributes.

  • :scopes (String)

    Scopes.

Returns:

  • (Array<WSDiscovery::Response>, WSDiscovery::Searcher)

    Returns an Array of probe responses. If the reactor is already running this will return a WSDiscovery::Searcher which will make its accessors available so you can get responses in real 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(options={})
  response_wait_time = options[:response_wait_time] || DEFAULT_WAIT_TIME
  responses = []

  multicast_searcher = proc do
    EM.open_datagram_socket('0.0.0.0', 0, WSDiscovery::Searcher, options)
  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