class

TCPSocket

Inherits IPSocket < Socket < Crystal::System::Socket < IO::Buffered < IO < Reference < Object

A Transmission Control Protocol (TCP/IP) socket.

NOTE: To use TCPSocket, you must explicitly import it with require "socket"

Usage example:

require "socket"

client = TCPSocket.new("localhost", 1234)
client << "message\n"
response = client.gets
client.close

Constructors

new(host : String, port : Int32, dns_resolver : DNS::Resolver, connect_timeout : Int | Time::Span | Nil = nil, caller : Symbol | Nil = nil, answer_safety_first : Bool | Nil = nil, addrinfo_overridable : Bool | Nil = nil) : TCPSocket
Source
new(ip_address : IPAddress, dns_timeout = nil, connect_timeout = nil, blocking = false)
Source