next up previous
Next: About this document ... Up: proj01 Previous: proj01

Project 1: Building a Phone Directory Service System

  1. Description

  2. Data Transfer
  3. Error Handling
    Most system calls will return -1 as an error indicator. The server and client programs should handle as many error conditions as possible.

  4. Grading Policy and Submission Requirement
    1. Two to five students will work together on this project. No more than three CS graduate students are allowed in one group. A too small or too big number of group members, say 2 or 5, will affect your grade negatively. Each group should only submit your project once. Both hardcopy and the electronic copy are required. A cover page is required for the hard copy. The cover page should contain the following information: the course name, your names and user account names, the project name, your majors, student status (undergraduate or graduate student), and so on.

    2. Your grade comes from three parts:
      • Executable programs (70%)
      • Program Stability (10%)
      • Documents (README, Makefile, user guide, design report) (20%)

    3. Each group should write a design report which contains the following material:
      • The protocol design, including the definition of the request and the response (meaning and format), the physical layout of the request and the response.
      • The user interface design of the your client program. It should look like the user guide to your application program.
      • The skeletons of server and client programs, including the explanation of the working process for both the server and the client, the error handling conditions, and so on.
      • Proper in-line comments are required.

    4. The README file should contain the following information:
      • A detailed contribution list describing each student's contribution to the project. The description should be very specific. Vague accounts should be avoided.
      • Instructions to build your application programs.
      • Instructions to test your application programs.
      give a detailed contribution list describing each student's contribution to the project. It should be specific.

  5. Database Processing
    1. Using the UNIX Database Library (libgdbm.a)
      DBM is a library of routines that manages data files that contain key/data pairs. The access provided is that of storing, retrieval, and deletion by key and a non-sorted traversal of all keys. (type 'man gdbm' to get the man pages)
    2. Example db.c
      #include    <stdio.h>
      #include    <gdbm/ndbm.h>
      #include    <fcntl.h>
      
      void error (const char *msg)
      {
          fprintf (stderr, "%s\n", msg);
          exit (-1);
      }
      
      struct {
          char *name;
          char *phone;
      } data [] = {
          {"D. C. Lynch", "(316)999-4444"},
          {"M. W. Joy",   "(316)999-4445"},
          {"J. Peterson", "(316)999-4446"},
      };
      
      int main (int argc, char **argv)
      {
          DBM     *db;
          datum   key, value;
          int     i;
      
          db = dbm_open ("yellowpage", O_RDWR | O_CREAT, 0666);
      
          if (db == NULL)
              error ("could not open the database");
      
          /* store data into the database */
          for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) {
              key.dptr = data[i].name;
              key.dsize = strlen (data[i].name) + 1;
      
              value.dptr = data[i].phone;
              value.dsize = strlen (data[i].phone) + 1;
              if (dbm_store (db, key, value, DBM_REPLACE) != 0) 
                  fprintf (stderr, "could not store (%s, %s)\n", 
                           data[i].name, data[i].phone);
          }
      
          /*  traverse the whole database */
          for(key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) {
              value = dbm_fetch(db, key);
              printf ("%s\t%s\n", key.dptr, value.dptr);
          }
      
          /* serch the value in the database whose key is specified*/
          key.dptr = "J. Peterson";
          key.dsize = strlen ("J. Peterson") + 1;
          value = dbm_fetch (db, key);
          printf ("%s\t%s\n", key.dptr, value.dptr);
      
          /* serch the key in the database */
          dbm_delete (db, key);
          value = dbm_fetch (db, key);
          if (value.dptr == NULL)
              printf ("phone number for %s is unknown\n", key.dptr);
      
          dbm_close (db);
      }
      
      To compile the code, you can use the following command:
      % gcc db.c -o db -lgdbm  
      		

  6. Some Suggestions

next up previous
Next: About this document ... Up: proj01 Previous: proj01
2001-10-03
Hosted by www.Geocities.ws

1