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
-
4.0
-
Socket.tcp&TCPSocket.newaccepts anopen_timeoutkeyword argument to specify the timeout for the initial connection. [Feature #21347] -
When a user-specified timeout occurred in
TCPSocket.new, eitherErrno::ETIMEDOUTorIO::TimeoutErrorcould previously be raised depending on the situation. This behavior has been unified so thatIO::TimeoutErroris now consistently raised. (Please note that, inSocket.tcp, there are still cases whereErrno::ETIMEDOUTmay be raised in similar situations, and that in both casesErrno::ETIMEDOUTmay be raised when the timeout occurs at the OS level.)
-