Receiving Messages - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Using UNIX Domain Datagram Sockets
Sending and Receiving Messages
Function result: number of bytes actually sent if sendto succeeds, -1 if
sendto call fails.
Example:
struct
...
count = sendto(s, argv[2], strlen(argv[2]), 0,
&servaddr,
sizeof(struct sockaddr_un);
When to Send Data
The server or client process should send data after server has bound to
an address. Refer to the send(2) man page for more information on
sendto and sendmsg.

Receiving Messages

Use recvfrom or recvmsg to receive messages. recvmsg is similar to
recvfrom, except recvmsg allows the read data to be scattered into
buffers.
recv can also be used if you do not need to know what socket sent the
message. However, if you want to send a response to the message, you
must know where it came from. Except for the extra information
returned by recvfrom, the two calls are identical. recvfrom and its
parameters are described in the following table.
Include files:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
System call:
count = recvfrom(s, msg, len, flags, from,
fromlen)
int s;
char *msg;
int len, flags;
struct sockaddr_un *from;
int *fromlen;
156
sockaddr_un
servaddr;
Chapter 7

Advertisement

Table of Contents
loading

Table of Contents