Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
IPSocket#recvfrom
ipsocket.recvfrom(maxlen) => [mesg, ipaddr]
ipsocket.recvfrom(maxlen, flags) => [mesg, ipaddr]
ext/socket/ipsocket.c
View on GitHub ↗
static VALUE
ip_recvfrom(int argc, VALUE *argv, VALUE sock)
{
return rsock_s_recvfrom(sock, argc, argv, RECV_IP);
}
Receives a message and return the message as a string and an address which the message come from.
maxlen is the maximum number of bytes to receive.
flags should be a bitwise OR of Socket::MSG_* constants.
ipaddr is the same as IPSocket#{peeraddr,addr}.
Example
u1 = UDPSocket.new u1.bind("127.0.0.1", 4913) u2 = UDPSocket.new u2.send "uuuu", 0, "127.0.0.1", 4913 p u1.recvfrom(10) #=> ["uuuu", ["AF_INET", 33230, "localhost", "127.0.0.1"]]