D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby18
/
share
/
ri
/
1.8
/
system
/
Socket
/
Filename :
recvfrom-i.yaml
back
Copy
--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Receives up to <em>maxlen</em> bytes from <tt>socket</tt>. <em>flags</em> is zero or more of the <tt>MSG_</tt> options. The first element of the results, <em>mesg</em>, is the data received. The second element, <em>sender_sockaddr</em>, 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: <tt>maxlen</tt> - the number of bytes to receive from the socket - !ruby/struct:SM::Flow::LI label: "*" body: <tt>flags</tt> - zero or more of the <tt>MSG_</tt> 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 <em>recvfrom</em> fails:" - !ruby/object:SM::Flow::LIST contents: - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EAGAIN - the <tt>socket</tt> 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 <tt>socket</tt> file descriptor is marked as O_NONBLOCK or the <tt>socket</tt> 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 <tt>socket</tt> 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 <em>recvfrom</em> 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 <tt>socket</tt> 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 <em>recvfrom</em> 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 <tt>socket</tt> 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 - <tt>socket</tt> has not been bound with a call to <em>bind</em>, 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 <tt>socket</tt> was zero or negative - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EISCONN - <tt>socket</tt> is already connected. The call to <em>recvfrom</em> 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 <tt>socket</tt> is not stream-style such as type SOCK_STREAM. OOB data is not supported in the communication domain associated with <tt>socket</tt>, or <tt>socket</tt> is unidirectional and supports only send operations - !ruby/struct:SM::Flow::LI label: "*" body: Errno::ESHUTDOWN - <tt>socket</tt> has been shutdown. It is not possible to call <em>recvfrom</em> on a socket after <em>shutdown</em> has been invoked. - !ruby/struct:SM::Flow::LI label: "*" body: Errno::EWOULDBLOCK - <tt>socket</tt> is marked as nonblocking and a call to <em>recvfrom</em> 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