Function SocketRecvFrom() Professional

Receives a datagram and stores the sender's address.

SocketRecvFrom( <nSocket>     , ;
                @<cBuffer>    , ;
                [<nLength>]   , ;
                [<nFlag>]     , ;
                [@<aFromAddr>], ;
                [@<nError>]     ) --> nBytesWritten
This is a numeric socket descriptor identifying a bound but unconnected socket.
A character string serving as buffer for the incoming data must be passed by reference.
Optionally, the number of bytes to read can be specified. This parameter defaults to Len(<cBuffer>).
#define constants from the file SOCKET.CH are used for this parameter. It specifies the way in which the call is made.
Constants for data retrieval
Constant Description
MSG_NORMAL *) Copy incoming data to <cBuffer> and remove copied data from the input queue.
MSG_PEEK Copy incoming data to <cBuffer> and leave the data in the input queue.
MSG_OOB Process out-of-band data.
  1. default
If passed by reference, an array containing IP address information of the sender of the datagram is assigned to <aFromAddr>. The following #define constants are available in the file SOCKET.CH to access the individual array elements:
Constants for the IP address array
Constant Description
IPADDR_ADDR Numeric IP address in network byte order.
IPADDR_FAMILY Address family (Windows sockets support only AF_INET).
IPADDR_PORT Number of port the socket is associated with.
If this parameter is passed by reference to the function, it gets assigned a numeric error code when the function fails. #define constants beginning with WSAE are available in the file SOCKET.CH to identify an error condition.

Returns the number of bytes read from the input queue or 0 in case of a failure.


This function is typically used to receive datagrams on unconnected sockets. However, the function can be called on any datagram socket, be it connected or unconnected. SocketRecvFrom() copies incoming data into a buffer and may be used to obtain a datagram sender's address data. The number of bytes read from the input queue is returned. When a datagram is received that is too long to fit into the buffer, excess data is discarded. If no datagram is available, the function blocks waiting for a message to arrive, unless the socket is in nonblocking mode.


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.