Skip to content

Instantly share code, notes, and snippets.

@flano-yuki flano-yuki/client.rb Secret
Last active Dec 30, 2019

Embed
What would you like to do?
#!/usr/bin/ruby
require "socket"
require 'timeout'
udps = []
5.times do
udps << UDPSocket.open()
end
addrs = []
5.times do
addrs << Socket.pack_sockaddr_in(10000, "NLB Endpoint") #編集
end
while true do
5.times do |i|
begin
Timeout.timeout(3) do
udps[i].send("HELLO", 0, addrs[i])
print "#{udps[i].recv(65535)} "
end
rescue Timeout::Error
print '(timeout) '
end
end
puts ""
sleep 3
end
#!/usr/bin/ruby
require "socket"
host = Socket.gethostname
Socket.udp_server_loop(10000) do |data, src|
src.reply host
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.