Name
TCPSocket — TCP/IP socket class
Synopsis
TCPSocket
is a class for Transmission
Control Protocol (TCP), which is connection-oriented, reliable
protocol.
Required Library
require ’socket’
Example
require 'socket' host=(if ARGV.length == 2; ARGV.shift; else "localhost"; end) print("Trying ", host, " ...") STDOUT.flush s = TCPsocket.open(host, ARGV.shift) print(" done\n") print("addr: ", s.addr.join(":"), "\n") print("peer: ", s.peeraddr.join(":"), "\n") while gets( ) s.write($_) print(s.readline) end s.close
Inherited Class
IPSocket
Class Methods
TCPSocket::new(
host
,
service
)
TCPSocket::open(
host
,
service
)
Opens a TCP connection to
host
forservice
, which may also be a port number
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.