我如何向多个接收者发送一条消息?
这基本上就是我想做的事情:
require 'socket'
ip = ['IP 1', 'IP 2']
port = 18000
loop {
message = gets.chomp()
conn = TCPSocket.open(ip, port)
conn.write(message)
conn.close_write
}
答案 0 :(得分:0)
尝试迭代ips数组:
ips = ['IP 1', 'IP 2']
port = 18000
loop do
message = gets.chomp()
ips.each do |ip|
conn = TCPSocket.open(ip, port)
conn.write(message)
conn.close_write
end
end