Open a socket to host and port Read lines from the socket : TCPSocket « Network « Ruby






Open a socket to host and port Read lines from the socket


require 'socket'                # Sockets are in standard library

host, port = ARGV               # Host and port from command line

s = TCPSocket.open(host, port)  # Open a socket to host and port
while line = s.gets             # Read lines from the socket
  puts line.chop                # And print with platform line terminator
end
s.close                         # Close the socket when done

 








Related examples in the same category

1.Read from a tcp server
2.connect to Ruby's Web server