Domain name resolver.
On most platforms, DNS queries are currently resolved synchronously. Calling a resolve method blocks the entire thread until it returns. This can cause latencies, especially in single-threaded processes.
DNS queries resolve asynchronously on the following platforms:
NOTE Follow the discussion in Async DNS resolution (#13619) for more details.
Resolves a domain that best matches the given options.
Resolves a domain that best matches the given options.
Resolves a domain for the TCP protocol with STREAM type, and yields each possible Addrinfo.
Resolves a domain for the UDP protocol with DGRAM type, and yields each possible Addrinfo.
Appends this struct's name and instance variables names and values to the given IO.
Returns an IPAddress matching this addrinfo.
Crystal::System::Addrinfo
Crystal::System::Addrinfo
Struct
Struct
Value
Object
Object
Object
Resolves a domain that best matches the given options.
mail or http services for example.Family::UNSPEC
Type::STREAM) and must be specified.Protocol::TCP) and should be specified.IO::TimeoutError is raised. Currently this is only supported on Windows.Example:
require "socket"
addrinfos = Socket::Addrinfo.resolve("example.org", "http", type: Socket::Type::STREAM, protocol: Socket::Protocol::TCP) Resolves a domain that best matches the given options.
Yields each possible Addrinfo resolution since a domain may resolve to many IP. Implementations are supposed to try all the addresses until the socket is connected (or bound) or there are no addresses to try anymore.
Raising is an expensive operation, so instead of raising on a connect or bind error, just to rescue it immediately after, the block is expected to return the error instead, which will be raised once there are no more addresses to try.
The iteration will be stopped once the block returns something that isn't an Exception (e.g. a Socket or nil).
Appends this struct's name and instance variables names and values to the given IO.
struct Point def initialize(@x : Int32, @y : Int32) end end p1 = Point.new 1, 2 p1.to_s # "Point(@x=1, @y=2)" p1.inspect # "Point(@x=1, @y=2)"
Returns an IPAddress matching this addrinfo.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Socket/Addrinfo.html