Class UDPSocket
In: lib/resolv-replace.rb
ext/socket/socket.c
Parent: Object

Methods

External Aliases

bind -> original_resolv_bind
connect -> original_resolv_connect
send -> original_resolv_send

Public Instance methods

Receives up to maxlen bytes from udpsocket using recvfrom(2) after O_NONBLOCK is set for the underlying file descriptor. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_inet_addr, is an array to represent the sender address.

When recvfrom(2) returns 0, Socket#recvfrom_nonblock returns an empty string as data. It means an empty packet.

Parameters

  • maxlen - the number of bytes to receive from the socket
  • flags - zero or more of the MSG_ options

Example

     require 'socket'
     s1 = UDPSocket.new
     s1.bind("127.0.0.1", 0)
     s2 = UDPSocket.new
     s2.bind("127.0.0.1", 0)
     s2.connect(*s1.addr.values_at(3,1))
     s1.connect(*s2.addr.values_at(3,1))
     s1.send "aaa", 0
     IO.select([s2])
     p s2.recvfrom_nonblock(10)  #=> ["aaa", ["AF_INET", 33302, "localhost.localdomain", "127.0.0.1"]]

Refer to Socket#recvfrom for the exceptions that may be thrown if the call to recvfrom_nonblock fails.

UDPSocket#recvfrom_nonblock may raise any error corresponding to recvfrom(2) failure, including Errno::EAGAIN.

See

[Validate]

ruby-doc.org is a service of James Britt and Rising Tide Software, a Ruby application development company in Phoenix, AZ.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.