Network Programming

Homework 5
Frequently Asked Questions

Question:  Can you point me to a good testing client?
Answer:  

Check out the apache benchmark program, installed as /usr/apache/bin/ab on the CS Suns. For usage information check out the man page:

man -M /usr/apache/man ab
 
Question:  I handle the zombie processes just like the book does. But on SUN workstation, the program only terminates the first child (the message is printed). New children after the first one seem to become zombies and the program does nothing about them. I tried the exactly same code on monica (FreeBSD). Everything on monica was perfect. Is there anything specific to SUN I can do?
Answer:  You have to be careful when using the old style signal handling function signal. On some operating systems (Solaris is one example), you need to re-assert the signal handler every time the signal is received. So on a Sun, if you are using signal (instead of the POSIX signal handling functions) you need to call signal at the end of the signal handler you install for SIGCHLD. On Solaris you can actually handle zombies by simply doing this:
signal(SIGCHLD,SIG_IGN);

This tells the OS to ignore SIGCHLD and to take care of zombies (it handles everything for you).

The book does sortof mention this issue, although it's not real clear, and easy to miss since the book's wrapper for signal (the Signal function) is actually using the POSIX signal handling functions (and avoids the re-assert issue).

 
Question:  Is our server supposed to connect to a "real server" to get documents, or just send back local files?
Answer:  Just local files - you do not need to contact any web servers. You should expect a request-line that looks like GET /foo.gif HTTP/1.0, not GET /www.rpi.edu/foo.gif HTTP/1.0
 
Question:  Help - text works fine (HTML) but images don't work!
Answer:  Here are a few common problems:
  • Invalid or missing HTTP status line.
  • Invalid or missing Content-type header.
  • Invalid of missing Content-length header.
  • Invalid line termination (should be \r\n).
  • Missing blank line to end HTTP headers.
  • Adding document <HEAD> section (don't add anything to an image!).
  • Not sending the entire image.
  • Trying to use fgets to read from the file (handles newlines as a special case - you need to treat newlines the same as any other character!).
  • Using some varient of printf to send. (what if the image file contains a byte that has the same value as the ACII code for '%'?). Use write() to send the data!
 
Question:  The sample threaded server code (chat server) doesn't call pthread_detach() or set the thread state to detached when creating new threads - isn't this suppose to happen (since your threads are never "joined")?
Answer:  Yes - this should happen. The code now includes a call to pthread_detach(pthread_self()) inside the function each thread runs.
 
Question:  How do I find out how big a file is (so I can send a content-length header)?
Answer:   Use the stat() system call. Here is an example:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
  struct stat s;

  if (! stat(argv[1],&s)) {
    printf("File size is %d\n",s.st_size);
  }

  return(0);
}

 
Question:  What is a zombie process, and how do I avoid generating them?
Answer:  Check out chapter 5 of the text.