1 # socket example - client side
2 # usage: ruby clnt.rb [host] port
3
4 require "socket"
5
6 host=(if ARGV.length == 2; ARGV.shift; else "localhost"; end)
7 print("Trying ", host, " ...")
8 STDOUT.flush
9 s = TCPSocket.open(host, ARGV.shift)
10 print(" done\n")
11 print("addr: ", s.addr.join(":"), "\n")
12 print("peer: ", s.peeraddr.join(":"), "\n")
13 while gets()
14 s.write($_)
15 print(s.readline)
16 end
17 s.close