RecvFrom

Read syntax diagramSkip visual syntax diagram SOCKET ( ' RECVFROM ' , socketid ,10000,'',10000maxlength,'',recvflags )

Purpose

Use the RecvFrom function to receive data on a socket, up to a specified maximum number of bytes, and get the sender's address. By specifying option flags, you can also:
  • Receive out-of-band data
  • Peek at the incoming data without removing it from the buffer

On a datagram socket, if more than the number of bytes requested is available, RecvFrom discards the excess bytes. If less than the number of bytes requested is available, RecvFrom returns the number of bytes available.

For stream sockets, data is processed as streams of information with no boundaries separating the data. For example, if programs A and B are connected with a stream socket, and program A sends 1000 bytes, each call to RecvFrom can return any number of bytes, up to the entire 1000 bytes. The number of bytes returned is specified in the return values string. Therefore, programs using stream sockets should place RecvFrom in a loop that repeats until all the data has been received. If a data length of zero is returned in the return values string, the socket has been closed by the other side.

If data is not available at the socket, RecvFrom waits for data to arrive and blocks the caller, unless the socket is in nonblocking mode.

Parameters

socketid
is the identifier of the socket.
maxlength
is the maximum length of data to be received. This is a number of bytes between 1 and 100000. If a number larger than the upper limit of 100000 is given, it will be replaced with 100000. If not specified, the default of 10000 is used.
recvflags
are flags that control the RecvFrom operation:
MSG_OOB or OOB or OUT_OF_BAND
Read out-of-band data on the socket. Only AF_INET stream sockets support out-of-band data.
MSG_PEEK or PEEK
Look at the data on the socket but do not change or destroy it.
''
Receive the data. No flag is set. This is the default.

Return Values

If successful, this function returns a string containing return code 0, the network address (domain, remote port, and remote IP address) of the sender, the length of the data received, and the data received. If unsuccessful, this function returns a string containing a nonzero return code, an error name, and an error message.

Examples

Call
Return Values
Socket('RecvFrom',6)
'0 AF_INET 5678 9.4.3.2 9 Data line'

The C socket call is: recvfrom(s, buf, len, flags, name, namelen)

Messages and Return Codes

For a list of REXX Sockets system messages, see REXX Sockets System Messages. For a list of REXX Sockets return codes, see REXX Sockets Return Codes.