Lab 8: Server Roulette

In this lab you'll modify your database server to be part of a networked group of servers, then you will randomly connect to one of your classmates and try to find out whose it is.

Goals:

  1. Update your server to load a database when it starts
  2. Update your server to register with a central database "tracker"
  3. Modify your client to get a random database server
  4. Update your client to perform a search on a remote server

Update your SVN repository on your Pi. Do all your work for this lab in the lab08 directory in your repository. When you're finished, check in your code.

Testing: the automated tests will not test the work you do in this lab. For this lab, you'll have to verify your server and client work using your partner's Pi, the instructor's Tracker, and by working with other teams.

Part 1: Importing on startup and Kill

As your first step, make your server import a file when it starts up. Right now, when you start the server it has an empty database. You will now specify a file to import when you run the server:

pi$ ./server data.txt
  1. Add code to server.c so when it starts, it imports a file.
  2. Create a file that can be imported. Make sure there are entries with a "name" value equal to your usernames. For example, I created a file with this content:

    bob => notme
    stammsl => ownsthis
    alice => notme
    taylormt => issleepy
    galluzzi => rocks
    
  3. Add a new command to the server, 'k', that the client can send to the server. When issued, this command causes the server to inform the client the server is shutting down, then disconnects from the client and closes down the server.

    HINT: Don't just call exit() to do this -- make sure you return from handleRemoteInput so the main function can clean up.

Part 2: Using the Tracker from your server

Your instructor will provide you with the IP address for the tracker. The tracker responds to three commands:

Example communication with the tracker using its protocol (server on left, tracker on right):

S >> REGISTER >> T
S << HELLO <IP address> << T
(disconnect)

S >> UNREGISTER >> T
S << GOODBYE <IP address> << T
(disconnect)

S >> RANDOM >> T
S << TALKTO <IP address> << T
(disconnect)

Implement sendTrackerCommand

Finish the function sendTrackerCommand in server.c to:

  1. Connect to the tracker (HINT: look for TRACKER_ADDR and TRACKER_PORT in the file and update those)
  2. Send to the tracker the command string in the argument
  3. Print out any response from the tracker to stdout
  4. Disconnect from the tracker

See the comments in server.c for more details.

Register and Un-register with the tracker

  1. Update the main function to register with the tracker before runServer.
  2. Update the main function to un-register with the tracker once runServer returns.
  3. Be sure to test out your register and unregister. Ask your instructor if you want to see if the registration and unregistration succeed.
  4. Launch your server and then print out the instructor verification sheet. Show your instructor and have them verify registration and unregistration work.

Part 3: Connecting your Client to a Random Server

Keep your server running for the rest of this lab. If it crashes or is killed, re-launch it. Other students may try to connect to it!

Now it's time to update your client to pick a random server for connecting. Make the following changes:

  1. Finish getRandomServer. This function connects to the tracker, gets a random server from it, and then stores the IP address in randomIP. See comments in client.c for details.
  2. Add the 'r' command to the client's runloop. It is almost exactly like 'c', but will get the IP address from the tracker instead of the user.
  3. Verify that you can connect to a remote server! Try it out. Identify whose server it is by looking at the server's contents.
  4. Get your instructor's signature on your instructor verification sheet!

Finishing the Lab

  1. Make sure any files you've created are added to SVN.
  2. Ensure your name and your partner's names are on all the files you edited.
  3. Commit your files to SVN. Only one of you two must commit the code to SVN, but both your names must be on all files you changed. It's a good idea to make sure your partner also has the code. If you both check it in, make sure BOTH names are on BOTH copies.
  4. Hand in one instructor verification sheet in hardcopy (with both your names on it).