Module | Easyjour |
In: |
lib/easyjour/version.rb
lib/easyjour.rb lib/easyjour/version.rb lib/easyjour.rb |
Version | = | '0.0.4' |
Version | = | '0.0.4' |
Initiaites a service search, returns an Easyjour::Search. Search will continue until stop is called. Can be given a block for immediate result processing.
# Find the HTTP servers that respond in 5 seconds or less search = Easyjour.search('http') sleep 5 search.stop search.results.each do |result| # access the entire result set puts "http://#{result.target}:#{result.port}/" end # Continously find HTTP servers search = Easyjour.search('http') do |result| puts "http://#{result.target}:#{result.port}/" end search.results # result set is updated as servers respond
# File lib/easyjour.rb, line 57 57: def self.search(service, protocol = :tcp, &block) 58: Search.new(service, protocol, &block) 59: end
Initiaites a service search, returns an Easyjour::Search. Search will continue until stop is called. Can be given a block for immediate result processing.
# Find the HTTP servers that respond in 5 seconds or less search = Easyjour.search('http') sleep 5 search.stop search.results.each do |result| # access the entire result set puts "http://#{result.target}:#{result.port}/" end # Continously find HTTP servers search = Easyjour.search('http') do |result| puts "http://#{result.target}:#{result.port}/" end search.results # result set is updated as servers respond
# File lib/easyjour.rb, line 57 57: def self.search(service, protocol = :tcp, &block) 58: Search.new(service, protocol, &block) 59: end
Makes a new service discoverable. Service is discoverable until stop is called.
# garbage_files is an HTTP server available on port 3000 Easyjour.serve("garbage_files", 'http', 3000)
# File lib/easyjour.rb, line 20 20: def self.serve(name, service, port, text_record = {}, protocol = :tcp) 21: Service.new(name, service, port, text_record, protocol = :tcp) 22: end
Makes a new service discoverable. Service is discoverable until stop is called.
# garbage_files is an HTTP server available on port 3000 Easyjour.serve("garbage_files", 'http', 3000)
# File lib/easyjour.rb, line 20 20: def self.serve(name, service, port, text_record = {}, protocol = :tcp) 21: Service.new(name, service, port, text_record, protocol = :tcp) 22: end
Searches for a service for timeout seconds and returns the results after stopping the search. Can be given a block for immediate result processing.
# Find the Git servers that respond in 5 seconds or less results = Easyjour.search(5, 'git') results.each do |result| puts "git://#{result.target}:#{result.port}" end
# File lib/easyjour.rb, line 69 69: def self.synchronous_search(timeout, service, protocol = :tcp, &block) 70: search = Search.new(service, protocol, &block) 71: sleep timeout 72: search.stop 73: search.results 74: end
Searches for a service for timeout seconds and returns the results after stopping the search. Can be given a block for immediate result processing.
# Find the Git servers that respond in 5 seconds or less results = Easyjour.search(5, 'git') results.each do |result| puts "git://#{result.target}:#{result.port}" end
# File lib/easyjour.rb, line 69 69: def self.synchronous_search(timeout, service, protocol = :tcp, &block) 70: search = Search.new(service, protocol, &block) 71: sleep timeout 72: search.stop 73: search.results 74: end
Turns a service and protocol into _service._protocol format, automatically defaults to TCP if no protocol is specified. Also gracefully handles a service that is already in the _service._protocol format format.
# File lib/easyjour.rb, line 8 8: def self.type_from_parts(service, protocol = :tcp) 9: if service =~ /^_\w+\._\w+$/ 10: service 11: else 12: "_#{service}._#{protocol}" 13: end 14: end
Turns a service and protocol into _service._protocol format, automatically defaults to TCP if no protocol is specified. Also gracefully handles a service that is already in the _service._protocol format format.
# File lib/easyjour.rb, line 8 8: def self.type_from_parts(service, protocol = :tcp) 9: if service =~ /^_\w+\._\w+$/ 10: service 11: else 12: "_#{service}._#{protocol}" 13: end 14: end