End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
UDPSocket#bind
udpsocket.bind(host, port) #=> 0
ext/socket/udpsocket.c
View on GitHub ↗
static VALUE
udp_bind(VALUE sock, VALUE host, VALUE port)
{
struct udp_arg arg;
VALUE ret;
GetOpenFile(sock, arg.fptr);
arg.res = rsock_addrinfo(host, port, rsock_fd_family(arg.fptr->fd), SOCK_DGRAM, 0);
ret = rb_ensure(udp_bind_internal, (VALUE)&arg,
rsock_freeaddrinfo, (VALUE)arg.res);
if (!ret) rsock_sys_fail_host_port("bind(2)", host, port);
return INT2FIX(0);
}
Binds udpsocket to host:port.
Example
u1 = UDPSocket.new u1.bind("127.0.0.1", 4913) u1.send "message-to-self", 0, "127.0.0.1", 4913 p u1.recvfrom(10) #=> ["message-to", ["AF_INET", 4913, "localhost", "127.0.0.1"]]