Socket Programming Question:
Download Job Interview Questions and Answers PDF
What this function recvfrom() does?
![Socket Programming Interview Answer Socket Programming Interview Question](https://globalguideline.com/public/images/interview/6.png)
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.
#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 Interview Questions And Answers
PDF
Previous Question | Next Question |
What this function sendto() does? | How to disposing of a Socket? |