--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Receives up to maxlen bytes from socket. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_sockaddr, contains protocol-specific information on the sender. - !ruby/struct:SM::Flow::H level: 3 text: Parameters - !ruby/object:SM::Flow::LIST contents: - !ruby/struct:SM::Flow::LI label: "*" body: maxlen - the number of bytes to receive from the socket - !ruby/struct:SM::Flow::LI label: "*" body: flags - zero or more of the MSG_ options type: :BULLET - !ruby/struct:SM::Flow::H level: 3 text: Example - !ruby/struct:SM::Flow::VERB body: " # In one file, start this first\n require 'socket'\n include Socket::Constants\n socket = Socket.new( AF_INET, SOCK_STREAM, 0 )\n sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )\n socket.bind( sockaddr )\n socket.listen( 5 )\n client, client_sockaddr = socket.accept\n data = client.recvfrom( 20 )[0].chomp\n puts "I only received 20 bytes '#{data}'"\n sleep 1\n socket.close\n\n # In another file, start this second\n require 'socket'\n include Socket::Constants\n socket = Socket.new( AF_INET, SOCK_STREAM, 0 )\n sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )\n socket.connect( sockaddr )\n socket.puts "Watch this get cut short!"\n socket.close\n" - !ruby/struct:SM::Flow::H level: 3 text: Unix-based Exceptions - !ruby/struct:SM::Flow::P body: "On unix-based based systems the following system exceptions may be raised if the call to recvfrom fails:" - !ruby/object:SM::Flow::LIST contents: - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EAGAIN - the socket file descriptor is marked as O_NONBLOCK and no data is waiting to be received; or MSG_OOB is set and no out-of-band data is available and either the socket file descriptor is marked as O_NONBLOCK or the socket does not support blocking to wait for out-of-band-data - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EWOULDBLOCK - see Errno::EAGAIN - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EBADF - the socket is not a valid file descriptor - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ECONNRESET - a connection was forcibly closed by a peer - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EFAULT - the socket's internal buffer, address or address length cannot be accessed or written - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EINTR - a signal interupted recvfrom before any data was available - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EINVAL - the MSG_OOB flag is set and no out-of-band data is available - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EIO - an i/o error occurred while reading from or writing to the filesystem - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENOBUFS - insufficient resources were available in the system to perform the operation - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENOMEM - insufficient memory was available to fulfill the request - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENOTCONN - a receive is attempted on a connection-mode socket that is not connected - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENOTSOCK - the socket does not refer to a socket - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EOPNOTSUPP - the specified flags are not supported for this socket type - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ETIMEDOUT - the connection timed out during connection establishment or due to a transmission timeout on an active connection type: :BULLET - !ruby/struct:SM::Flow::H level: 3 text: Windows Exceptions - !ruby/struct:SM::Flow::P body: "On Windows systems the following system exceptions may be raised if the call to recvfrom fails:" - !ruby/object:SM::Flow::LIST contents: - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENETDOWN - the network is down - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EFAULT - the internal buffer and from parameters on socket are not part of the user address space, or the internal fromlen parameter is too small to accomodate the peer address - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EINTR - the (blocking) call was cancelled by an internal call to the WinSock function WSACancelBlockingCall - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EINPROGRESS - a blocking Windows Sockets 1.1 call is in progress or the service provider is still processing a callback function - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EINVAL - socket has not been bound with a call to bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled, or (for byte stream-style sockets only) the internal len parameter on socket was zero or negative - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EISCONN - socket is already connected. The call to recvfrom is not permitted with a connected socket on a socket that is connetion oriented or connectionless. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ENETRESET - the connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EOPNOTSUPP - MSG_OOB was specified, but socket is not stream-style such as type SOCK_STREAM. OOB data is not supported in the communication domain associated with socket, or socket is unidirectional and supports only send operations - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ESHUTDOWN - socket has been shutdown. It is not possible to call recvfrom on a socket after shutdown has been invoked. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EWOULDBLOCK - socket is marked as nonblocking and a call to recvfrom would block. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EMSGSIZE - the message was too large to fit into the specified buffer and was truncated. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ETIMEDOUT - the connection has been dropped, because of a network failure or because the system on the other end went down without notice - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ECONNRESET - the virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket; it is no longer usable. On a UDP-datagram socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message. type: :BULLET full_name: Socket#recvfrom is_singleton: false name: recvfrom params: | socket.recvfrom(maxlen) => [mesg, sender_sockaddr] socket.recvfrom(maxlen, flags) => [mesg, sender_sockaddr] visibility: public