Class: Evesync::Discover
- Inherits:
-
Object
- Object
- Evesync::Discover
- Defined in:
- lib/evesync/discover.rb
Overview
Discover other nodes Handles discovering messages sending and receiving
Example
disc = Discover.new
disc.
...
disc.stop
Constant Summary collapse
- DISCOVERY_REQ =
'EVESYNC'.freeze
- DISCOVERY_ANS =
'DISCOVERED'.freeze
Instance Method Summary collapse
-
#initialize ⇒ Discover
constructor
A new instance of Discover.
-
#send_discovery_message(ip = '<broadcast>', message = DISCOVERY_REQ) ⇒ Object
Sending UDP message on broadcast Discovering our nodes.
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Discover
Returns a new instance of Discover.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/evesync/discover.rb', line 22 def initialize # Starting thread that sends and accepts UDP-packages. # This is how a node can say that it's online @evesync = IPC::Client.new( port: :evemond ) @port = Config[:evesyncd]['broadcast_port'] @listen_sock = UDPSocket.new @listen_sock.bind('0.0.0.0', @port) @listen_thread = Thread.new { listen_discovery } end |
Instance Method Details
#send_discovery_message(ip = '<broadcast>', message = DISCOVERY_REQ) ⇒ Object
Sending UDP message on broadcast Discovering our nodes
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/evesync/discover.rb', line 38 def (ip = '<broadcast>', = DISCOVERY_REQ) udp_sock = UDPSocket.new if ip == '<broadcast>' udp_sock.setsockopt( Socket::SOL_SOCKET, Socket::SO_BROADCAST, true ) end udp_sock.send(, 0, ip, @port) udp_sock.close end |
#stop ⇒ Object
49 50 51 |
# File 'lib/evesync/discover.rb', line 49 def stop @listen_thread.exit end |