/* random number server */ #include "simpleipc.c" #include "simpletcp.c" #define RPORT 30034 int main() { int sfd, cfd; int min, max, randnum; struct timeval tv; /* set random seed according to time of day */ gettimeofday(&tv,NULL); srandom(tv.tv_usec); sfd = creatListener(RPORT); if (sfd < 0) exit(1); printf("Random number server started ...\n"); while (1<2) // server loop { cfd = listenOn(sfd); // wait for client to send range of numbers min = readInt(cfd); max = readInt(cfd); randnum = min + (random() % (max-min+1)); writeInt(cfd,randnum); close(cfd); } // while exit(0); }