HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual page 144

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

Advertisement

Using UNIX Domain Stream Sockets
Example Using UNIX Domain Stream Sockets
*
PITCH - SEND DATA TO THE CATCHER
*
*
Pitch and catch set up a simple unix domain stream socket
*
client-server connection. The client (pitch) then sends
*
data to the server (catch), throughput is calculated, and
*
the result is printed to the client's stdout.
*/
#include <stdio.h>
#include <time.h>
#include <netdb.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SOCKNAME
#define BUFSIZE
char buffer[BUFSIZE];
struct bullet {
int bytes;
int throughput;
int magic;
} bullet = { 0, 0, 12345 };
send_data(fd, buf, buflen)
char *buf;
{
int cc;
while (buflen > 0) {
cc = send(fd, buf, buflen, 0);
if (cc == -1) {
perror("send");
exit(0);
}
buf += cc;
buflen -= cc;
}
}
recv_data(fd, buf, buflen)
char *buf;
{
int cc;
while (buflen > 0) {
cc = recv(fd, buf, buflen, 0);
if (cc == -1) {
perror("recv");
exit(0);
}
buf += cc;
buflen -= cc;
}
}
main( argc, argv)
int argc;
char *argv[];
{
int bufsize, bytes, cc, i, total, pid;
float msec;
struct timeval tp1, tp2;
int s, sendsize, secs, usec;
struct timezone tzp;
struct sockaddr_un sa;
144
"/tmp/p_n_c"
32*1024-1
Chapter 6

Advertisement

Table of Contents
loading

Table of Contents