Project 1, Part 3

Marvel Lookup from Web Page using a server program.
Due: October 14 - 11:55 pm

Moodle Link



This assignment addresses the performance issues of the previous version. In the previous version the index had to be rebuilt for EVERY lookup. BY creating a stand-alone server program, the web spawned program called by the web server can communicate with the server to retrieve the answers from the already constructed index.

If you go to here you can try out a version of the names program that uses a server:


(note: if the server isn't running, this program won't work!)

Your goal will be to design and build a version of the Marvel search that uses a server for the index.

US Census Name data program with server

You have been given the code to look up names in the US Census data. The architecture of the solution is seen below:


Get and install your own version

The github project is located at

To get your own:

  1. Log on to
  2. Type: "git clone" or
    "git clone"

Change the names

You will need to change the programs in three files to make it work correctly for you. You can use textwrangler or notepad++

1. Change the Makefile

Copy this project into a new folder in your folder. Then change the "user= skon" in the Makefile to be "user=username" where username is your server username.

2. Change the reference to the CGI program in the HTML file

In namelookupCS.html change the line:"GET", "/cgi-bin/skon_namelookupCS.cgi?"

so that skon is now your username. This makes sure your code is copied to the right directories, and with the correct names.

3. Change the Fifo names

For c++ In fifo.h change line 33:

const string SIG = "Skon_";

So that Skon is changed to you username.

For python change line 67:

  fifoname="skon" # unique name for fifos

to your username.

Run the program

To run the system go to the project folder (see above) in a ssh terminal.

  1. Make the project: make
  2. Run the server: ./nameserver or python3
  3. Go to your folder with a browser, and open namelookupCS.html

Create a new project

You will need to make a copy of the nameserver folder to use as the starting point for the new Marvel project. From your main directory make a copy:

cd ~
cp -r namesclientserver marvelproject

You will then need to change the file names, and then change the Makefile to make the changes in the filenames. You are required to use a makefile for this project.

Communication through Fifo's (C++)

The Fifos are special communication files that allow the CGI program to talk to the Name Server. This must be changed or we will all use the same Fifo's, and they will interfere with each other.

The CGI program is called from the Apache2 web server, so it must be in a special folder where web programs are allowed to run. This is the "/usr/lib/cgi-bin/" folder. The program running the lookups with the inverted index can be located in your own directory.

Communication between the CGI program that is called from the web server to the name server program is enabled by the FiFo communications object. This is a interprocess communication component that utilizes Linux system "pipes".

  • Fifo Pipes: The use of named pipes in C++. The demo code given to you includes a wrapper class "Fifo" which encapsulates the use of pipes for easy interprocess communication is C++. Please careful review the use in the demo code above it's use. Also note - creation of a pipe creates a special files in the /tmp folder on the Linex file system. In order to prevent file naming collisions you MUST modify the code in Fifo.h to use your username for the pipe "SIG" string constant. This is appended to the pipe names, assuring that all pipes are private for your program. Fifo methods
  Fifo();             // Default Constructor                                     
  Fifo(string);       // Construct from pipe name string                         
                      // If a pipe already exists, does nothing                  
                      // Otherwise it creates the names pipe                     

  void openread();    // Open a pipe for reading (recv)                          
                      // openread allows other readers but                       
                      // blocks writers from the pipe                            

  void openwrite();   // Start a pipe for writing (send)                          
                      // openwrite block all other opens to the pipe             
                      // blocked opens proceed with previous user                

  void fifoclose();   // Close the pipe                                          
                      // Frees the pipe for other users (processes)              

                      // You MUST call openread() before recv                    
  string recv();      // Receives - get the next record from the pipe            
                      // Process will vlock until pipe has data.                 

                      // You MUST call openwrite() before a send                 
  void send(string);  // Sends - a record into the pipe                          
                      // Does not block - always writes and returned 


Fifo Use

The fifo's in the sample program for the US census senda single request, and waits for a single response, which is a comma delimited list of 30 values. For example, if the user request the name Smith, the server responds with:


For this project what is returned is MUCH larger, for example the work king returns 3174's lines. The problem is that the fifo's can only handle 2000 characters at a time. The solution? You will need to send one line at a time back from the server to the client. This can be done with loop on both sides, with the server sending the lines, and the client receiving them, and then sending the, to the web page with a cout. However, the client need to know when the server is done sending. This can be done by sending a unique string that will never be in the data. Something like $END will work. Thus the client loops receiving strings until the server sends a $END.

Another problem is that the separation of the lines into separate lines in the bowser screens. An easy solution is the insert a between every line. This will cause the browser to place each line on a separate line.

Communication through Fifo's (Python)

The Fifos are special communication files that allow the CGI program to talk to the Name Server. This must be changed or we will all use the same Fifo's, and they will interfere with each other.

TheFifo 's work very much like reading and writing to files. You open the Fifo and write to it in one program, and open the Fifo and read from it in another. The reciever will not stop waiting inputing until the writing program closes the fifio.

Marvel Program

In project 1-1 and 1.2 you created code to lookup characters in the Marvel file. You will combine that code with the code from this US Name data system to make a web version of your Marvel lookup program.

You will need to make a copy of the namesclientserver folder with a new name, and copy the file over

  1. Go to your home directory: cd ~
  2. From your home directory make a new folder: mkdir project2
  3. Copy the contents of the demo names system to the folder: cp namesclientserver/* project2/

Next you will need to modify the program to serve up Marvel Character matches

  1. Rename the files as appropriate, change the Makefile to reflect these changes
  2. Change the server program (renames from nameserver.cpp) to receive a single word, and return a series of matching lines. Remove the name maps, replace with the shakespeare map.
  3. Modify the testclient.cpp file or file to test out the server.
  4. Modify the the HTML program (renamed from name_stats_ajax.html) to send a request with a single word, and then display the results after calling the CGI program.
  5. Modify the CGI program (renamed from namefetchajax.cpp) to receive a word from the web page, and send it to the name server through the Fifo. Then it will recieve the matching lines back, and send them to the web page.

Running the sever in the background

When you turn in your Shakespeare lab please set your server program to run continuously in the background so I can test it out. Assuming the name of your server is shakeserver do the following command:

nohup ./marvelserver &


nohup python3 &

The nohup command makes sure the program will continue to run after you log out. The & will make the program run in the background.

Don't run this way until the program is running reliably and is well tested.


Below is a list of features you can put in your program, along with the points. Notice that people with Data Structures must do more than studnets with only the introduction course to get 100 points (the perfect score) on the program. If you do more than 100 points, you getr extra credit.

RequirementData StructuresIntro ProgCommentsScore
Program uses client/server architecture 30 30
Program displays a list matching characters for name entered 10 20
Program displays a list matching characters for year entered 10 20
Program displays all information on a selected (clicked on) character from the list above 10 10
Well designed Web User Interface* 20 20
Program broken up into functionally cohesive functions* 5 5
Program has meaningful comments, good variable names, and good formatting* 5 5
Program uses appropriate classes 10 10
Program allows the searching for two or more names on the same search. (Extra Credit) 10 10

*These are required in order to get extra credit.

Turn in

  1. The program must be runnable. You must run the server with the "nohup ./MARVELserver &" command (use your program name).
  2. All source files you authored
  3. A writeup with the table above, and an indicated of which was included. Paste table into Moodle text field, and put X's in to options you attempted. Also include a statement of the highest computer science course you have taken.
  4. Several runs showing all features.

This topic: Main > WebHome > SoftDev2019 > SDProject1-3
Topic revision: r1 - 2020-01-23 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback