home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / gopher / gopher1.01 / misc / Radio / radiod / radiod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-11  |  2.9 KB  |  130 lines

  1. /*
  2.  *******************************************************************
  3.  * $Author: lindner $
  4.  * $Revision: 1.4 $
  5.  * $Date: 91/04/10 12:37:09 $
  6.  * $Source: /export/mermaid/staff/lindner/gopherd/RCS/gopherd.c,v $
  7.  *******************************************************************
  8.  */
  9.  
  10.  
  11. /* Derived from an 
  12.  * Example of server using TCP protocol
  13.  * pp 284-5 Stevens UNIX Network Programming
  14.  */
  15.  
  16. #include "gopherd.h"
  17.  
  18. char Zehostname[128];
  19. int GopherPort = GOPHER_PORT;
  20.  
  21. void
  22. main(argc, argv)
  23.   int     argc;
  24.   char     *argv[];
  25. {
  26.      int sockfd;
  27.      int newsockfd;
  28.      int clilen;
  29.      int childpid;
  30.      int i;
  31.  
  32.      struct sockaddr_in cli_addr;
  33.      struct sockaddr_in serv_addr;
  34.  
  35.  
  36.      pname = argv[0];
  37.  
  38.      /*** We probably shouldn't do this, since only one process can digitize 
  39.        simultaneously, but of course we hate defunct processes!  ***/
  40.  
  41.      daemon_start(0);
  42.  
  43.      /** Open a TCP socket (an internet stream socket **/
  44.      
  45.      if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  46.       err_dump("server: can't open stream socket");
  47.      
  48.      /*
  49.       * Bind our local address so that the client can send to us
  50.       */
  51.      
  52.      bzero((char *) &serv_addr, sizeof(serv_addr));
  53.      serv_addr.sin_family         = AF_INET;
  54.      serv_addr.sin_addr.s_addr     = htonl(INADDR_ANY);
  55.      serv_addr.sin_port        = htons(GopherPort);
  56.      
  57.      if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) <0)
  58.       err_dump("server: can't bind local address");
  59.      
  60.      listen(sockfd, 5);
  61.      
  62.      for ( ; ; ) {
  63.       /*
  64.        * Wait for a connection from a client process.
  65.        * This is an example of a concurrent server.
  66.        */
  67.       
  68.       clilen = sizeof(cli_addr);
  69.       newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr,
  70.                  &clilen);
  71.       
  72.       if (newsockfd < 0)
  73.            err_dump("server: accept error");
  74.       
  75.       if ( (childpid = fork()) < 0)
  76.            err_dump("server: fork error");
  77.       
  78.       else if (childpid == 0) {    /* Child process */
  79.            close(sockfd);        /* close original socket */
  80.  
  81.            if (gethostname(Zehostname, 128) !=0 )
  82.             strcpy(Zehostname, "<<no-name>>");
  83.  
  84.  
  85.            while(do_command(newsockfd)!=0);    /* process the request */
  86.            exit(0);
  87.       }
  88.       /** clean up any zombie children **/
  89.       sig_child();
  90.  
  91.       close(newsockfd);         /* parent process */
  92.      }
  93. }
  94.  
  95.  
  96. #define BUFSIZE 1464
  97.  
  98. int
  99. do_command(sockfd)
  100. int sockfd;
  101. {
  102.      FILE *Play;
  103.      unsigned char in[BUFSIZE];
  104.      register int i, j;
  105.  
  106.      char inputline[MAXLINE];
  107.      int length;        /* Length of the command line */
  108.  
  109.      /*** Send out the Banner Line ***/
  110. /*     writestring(sockfd, "gopher 1.0 sound server\r\n");*/
  111.      
  112.      /** Just ignore what ever the client sends to us and whack out sound **/
  113.      i = readline(sockfd, inputline, MAXLINE);
  114.  
  115. /*     writestring(sockfd, "+ Okee dokee, here comes the sound\r\n");*/
  116.  
  117.      Play = popen("record -v 10 -", "r");
  118.      while(1) {
  119.  
  120.       for (i= 0; i<BUFSIZE; i++)
  121.            in[i] = getc(Play);
  122.  
  123.       j = writen(sockfd, in, BUFSIZE);
  124.  
  125.      }
  126. }
  127.  
  128.  
  129.  
  130.