Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Addrinfo#bind

() -> ::Socket
() { (::Socket) -> void } -> void
bind() { |sock| ... }

creates a socket bound to self.

If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise.

Example
Addrinfo.udp("0.0.0.0", 9981).bind {|s|
  s.local_address.connect {|s| s.send "hello", 0 }
  p s.recv(10) #=> "hello"
}
See also #afamily #canonname .unix #connect also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0