Skip to content
On this page

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class · Ruby 4.1

TCPSocket

< IPSocket 1 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 1

Ruby version changes 2

  1. 4.0