Socket Programming Question:

What this function recvfrom() does?

Tweet Share WhatsApp

Answer:

Receiving on a Named Socket - recvfrom()

#include <sys/types.h>
#include <sys/socket.h>

int recvfrom(int s, char *msg, int len, int flags,struct sockaddr *from, int *fromlen)

This function allows a message msg of maximum length len to be read from a socket with descriptor s from the socket named by from and fromlen, where fromlen is the actual length of from. The number of characters actually read from the socket is the return value of the function. On error, -1 is returned and errno describes the error. flags may be 0, or may specify MSG_PEEK to examine a message without actually receiving it from the queue.

If no message is available to be read, the process will suspend waiting for one unless the socket is set to nonblocking mode (via an ioctl call).

The system I/O call read() can also be used to read data from a socket.

Download Socket Programming PDF Read All 62 Socket Programming Questions
Previous QuestionNext Question
What this function sendto() does?How to disposing of a Socket?