Read from a tcp server : TCPSocket « Network « Ruby






Read from a tcp server


require 'socket'
host = "localhost"
port = 12345
TCPSocket.open(host, port) do |s| # Use block form of open
  while line = s.gets
    puts line.chop
  end
end                               # Socket automatically closed

 








Related examples in the same category

1.Open a socket to host and port Read lines from the socket
2.connect to Ruby's Web server