Flat File DB

Due date

11:00 am, Friday, March 22

Submission

Please place all of files that you create for this project in a folder in your repo named flat-file-db.  Include a Makefile that compiles  your programs using $make.  Include a file named README (no file extension) that includes the public IP address of your AWS virtual machine and the name of your partner.  Run your server as a daemon on your AWS virtual machine.

You can run an executable named server as a daemon by executing the following command:

nohup ./server &

Note: all students should submit their team’s code in their personal GitHub repository and have their server running on their personal AWS virtual machine.

A Flat-file Database

When an ordinary ASCII file is use to store database records we call the file a flat-file database.  We’ll be using a comma separated value file named contacts.csv as a flat-file database to store people’s contact information.  Each line of the file will contain a record for a single person.  Each record will be a comma-separated list of data consisting of a person’s first name, last name, email address, and phone number.

If we added data to our contacts.csv file and dump the contents to the console using cat, we should see something like this:

jason,smith,bsmith@gmail.com,3155551212
alicia,turner,aturner@yahoo.com,5408286754

To begin, create an empty file named contacts.csv using the touch command on your AWS virtual machine.

Client/Server Protocol

When the client wishes to insert a record into the database, the client will write 120 bytes (holding the record data) to the server and then receive 4 bytes from the server (holding a result code).

Data Format

CLIENT INSERT REQUEST (120 bytes)

  • command: 4 bytes, value: 0x01
  • first name: 24 bytes, value: ASCII string
  • last name: 48 bytes, value: ASCII string
  • email address: 36 bytes, value: ASCII string
  • phone number: 8 bytes, value: integer

SERVER RESULT CODE (4 bytes)

  • value: 0x00 (Success)
  • value: 0x01 (Error – First name is null)
  • value: 0x02 (Error – Last name is null)
  • value: 0x03 (Error – Record with first and last name already exist)

The Server

Write a program in a file named flat-file-db-server.c that satisfies the following requirements:

When a connection is made, the server reads the data sent from the client and

  • If the first name is null, the sever sends a result code of 0x01 to the client
  • If the last name is null, the sever sends a result code of 0x02 to the client
  • If a record containing the first and last name already exists, the server sends a result code of 0x03 to the client
  • If a record was successfully added, the server send 0x00 to the client.

Note: the server does not have to read all 116 bytes at once.

The Client

Write a program in a file named contacts.c that satisfies the following requirements:

The program repeatedly displays the following menu:

  1. Insert New Contact
  2. Exit

If the user enters 1.  The program prompts the user for a first name, last name, email address, and phone number and reads in the user’s input.  The program should allow null strings.  Ideally we wouldn’t, but we want to test the server’s ability to send the appropriate result codes.  The client then sends the data to the server, reads the result code sent back from the server, and prints to the console a string describing the result (see result codes above).  Note:  the client does not have to send all 116 bytes at once.

If the user enters 2, the program gracefully terminates.

 

© 2019, Eric. All rights reserved.