This is used to receive a message from a connection-mode or connectionless-mode socket. Here it its syntax:
ssize_t recvfrom(int fdsock, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len);
Here, we need to address the following:
- fdsock: Represents the file descriptor of the socket.
- buffer: Represents the buffer where the message is stored.
- length: Represents the number of bytes of the buffer that are pointed to by the buffer parameter.
- flags: Represents the type of message that's received.
- address: Represents the sockaddr structure in which the sending address is stored. The length and format of the address depend on the address family of the socket.
- address_len: Represents the length of the sockaddr structure that's pointed to by the address parameter.
The function returns the length of the message that's written to the buffer, which is pointed to by the buffer argument.
Now, we can begin with the first part of this recipe: preparing a server to wait for and reply to a message from the client using a UDP socket.