Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.48 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.      while(1) {  // main accept() loop
  2.         sin_size = sizeof their_addr;
  3.         new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
  4.         if (new_fd == -1) {
  5.             perror("accept");
  6.             continue;
  7.         }
  8.         if(recv(new_fd, browserInput, sizeof browserInput, 0) == -1){
  9.                 perror("recv");
  10.         }
  11.        
  12.         printf("%s", browserInput);    
  13.        
  14.         if (fork() == 0) {
  15.                 sendPage();    
  16.         }
  17.         close(new_fd);  // parent doesn't need this
  18.     }