1998-01-16 15:13:05 +03:00
|
|
|
# socket example - client side
|
|
|
|
# usage: ruby clnt.rb [host] port
|
|
|
|
|
|
|
|
require "socket"
|
|
|
|
|
2002-12-19 23:26:16 +03:00
|
|
|
if ARGV.length >= 2
|
|
|
|
host = ARGV.shift
|
|
|
|
else
|
|
|
|
host = "localhost"
|
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
print("Trying ", host, " ...")
|
|
|
|
STDOUT.flush
|
2002-07-11 12:22:18 +04:00
|
|
|
s = TCPSocket.open(host, ARGV.shift)
|
1998-01-16 15:13:05 +03:00
|
|
|
print(" done\n")
|
|
|
|
print("addr: ", s.addr.join(":"), "\n")
|
|
|
|
print("peer: ", s.peeraddr.join(":"), "\n")
|
2002-12-19 23:26:16 +03:00
|
|
|
while line = gets()
|
|
|
|
s.write(line)
|
1998-01-16 15:13:05 +03:00
|
|
|
print(s.readline)
|
|
|
|
end
|
|
|
|
s.close
|