4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rollcall.rb', line 4
def self.call_roll
addr = ['<broadcast>', 33333]
sending_sock = UDPSocket.new
sending_sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
data = 'roll call!'
sending_sock.send(data, 0, addr[0], addr[1])
addr = ['0.0.0.0', 33334] BasicSocket.do_not_reverse_lookup = true
receiving_sock = UDPSocket.new
receiving_sock.bind(addr[0], addr[1])
server_info = {}
loop do
got_something_that_time = nil
if IO.select([receiving_sock], nil, nil, 2) data, addr = receiving_sock.recvfrom(1024)
got_something_that_time = true
hostname,num_cores = data.split
info = {cores: num_cores.to_i, role: "test_#{server_info.count}".to_sym}
server_info.store(hostname, info)
end
break unless got_something_that_time end
receiving_sock.close
sending_sock.close
server_info
end
|