home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / sharedmem / part01 / stream / reader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  729 b   |  39 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6. #include "inet.h"
  7.  
  8. char buf[2000];
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char **argv;
  13. {
  14.     int writer;
  15.     int cc;
  16.     int fd;
  17.     int fds = 0;
  18.  
  19.     /* if an arg is provided, use that as the hostname to look for the */
  20.     /* service */
  21.     fd = initport(PORT_NUMBER(2000),SERVER,SOCK_STREAM,(char *)0);
  22.     if (fd < 0) {
  23.         fprintf(stderr,"initport() = %d\n",fd);
  24.         exit(-1);
  25.     }
  26.  
  27.         while (TRUE) {
  28.         writer = select_server_stream(fd,&fds);
  29.         cc = sized_read(writer,buf,2000);
  30.         if (cc <= 0) {
  31.             printf("%d: EOF\n",writer);
  32.             close(writer);
  33.             continue;
  34.         }
  35.         printf("%d: %s\n",writer,buf);
  36.         if (cc == 1) cc = sized_write(writer,"1 char",6);
  37.     }
  38. }
  39.