sockets - Ruby - Send message to multiple IP addresses -
how go sending 1 message multiple receivers?
this do:
require 'socket' ip = ['ip 1', 'ip 2'] port = 18000 loop { message = gets.chomp() conn = tcpsocket.open(ip, port) conn.write(message) conn.close_write }
try iterate on ips array:
ips = ['ip 1', 'ip 2'] port = 18000 loop message = gets.chomp() ips.each |ip| conn = tcpsocket.open(ip, port) conn.write(message) conn.close_write end end