Skip to content
On this page
class · Ruby 4.0

TCPSocket

< IPSocket 2 class methods

TCPSocket represents a TCP/IP client socket.

A simple client may look like:

Example
require 'socket'

s = TCPSocket.new 'localhost', 2000

while line = s.gets # Read lines from socket
  puts line         # and print them
end

s.close             # close socket when done

Class methods 2

Ruby version changes 2

  1. 4.0