Method: UDPSocket#bind

Defined in:
udpsocket.c

#bind(host, port) ⇒ Object

Binds udpsocket to host:port.

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"]]


127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'udpsocket.c', line 127

static VALUE
udp_bind(VALUE self, VALUE host, VALUE port)
{
    struct udp_arg arg = {.io = self};

    arg.res = rsock_addrinfo(host, port, rsock_fd_family(rb_io_descriptor(self)), SOCK_DGRAM, 0);

    VALUE result = rb_ensure(udp_bind_internal, (VALUE)&arg, rsock_freeaddrinfo, (VALUE)arg.res);
    if (!result) {
        rsock_sys_fail_host_port("bind(2)", host, port);
    }

    return INT2FIX(0);
}