class

IPSocket

Inherits Socket / Crystal::System::Socket / IO::Buffered / IO / Reference / Object

NOTE: To use IPSocket, you must explicitly import it with require "socket/ip_socket"

Instance methods

bind(addr)
Source
close

Flushes and closes the underlying IO.

Source
connect(addr, timeout = nil, &)

Tries to connect to a remote address. Yields an IO::TimeoutError or an Socket::ConnectError error if the connection failed.

Source
ipv6_only=(val : Bool) : Bool

Sets whether an IPv6 socket will accept IPv4 clients / packets

require "socket"

server = UDPSocket.new(:inet6)
# enable IPv6 dual stack, accepting IPv4 clients
server.ipv6_only = false
server.bind "::1", 1234

message = Bytes.new(32)
bytes_read, client_addr = server.receive(message)
Source
ipv6_only?

Reports whether IPv4 packets are accepted by the socket.

Source
local_address

Returns the IPAddress for the local end of the IP socket.

Source
remote_address

Returns the IPAddress for the remote end of the IP socket.

Source