Due Date
11:59 pm, Wednesday March 27
All students must work on this assignment alone and submit their own work. Please place all source code in a repository folder named final_sockets_project. Name your client source code file contacts.c and name your server source code file contacts_server.c. Include a README file that includes the public IP address of your AWS server and a Makefile.
Your client and server should use port 8897 with the service name contacts.
Please start an instance of your server using the above port and service name and keep it running so that I can test it.
You can run an executable named server in the background by executing the following command:
nohup ./server &
The Client & the Server
Modify your client so that it displays the following menu.
- Insert contact
- List contacts
- Exit
If the user chooses 1 or 3, the client behaves as in the previous program.
If the user chooses 2, the following protocol should be followed.
- the client sends the value 0x02 (in 4 bytes) to the server representing a GET CONTACTS request.
- The server queries the database, determine the number of contacts in the database, and sends to the client the number of contacts (in 4 bytes).
- The server then sends to the client the contacts in the database (116 bytes each) and terminates the connection.
- The client reads from the server the number of contacts in the database (in 4 bytes).
- The client then reads the contacts sent by the server (116 bytes each) and prints them to standard out (i.e. the console).
Server Query
The following query string can be used to get all of the contacts in the database.
"SELECT * FROM Contacts_T"
Refer the the section titled Retrieving Data From the Database in the previous homework description for information on how to retrieve data from the database.
The Protocol
CLIENT – INSERT REQUEST (4 bytes + 116 bytes)
- request type: 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 – INSERT REQUEST RESULT (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)
CLIENT – GET CONTACTS REQUEST (4 bytes)
- request type: value: 0x02
SERVER – GET CONTACTS REQUEST RESULT (4 bytes + (number of contacts * 116 bytes))
- number of contacts: 4 bytes, value: integer
- 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
© 2019, Eric. All rights reserved.