Tags: %TAGME{ tpaction="" web="SCMP391" tag="" }% view all tags

Project 2

Shakespeare Lookup from Web Page
Due: February 10 - 11:55 pm

Moodle Link

Screen_Shot_2017-01-26_at_9.14.36_AM.png shake.gif


To take the code from project one that allows the looking up of words in Shakespeare though an inverted index, and create a web page version. Rather then write this from scratch you will reuse and modify the code provided for the US Census name server program.

US Census Name data program

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


The code for this US Census Name Data lookup system is located on cslab.kenyon.edu in the folder: /home/class/SoftDev/namesclientserver

Copy the program to your folder

  1. Go to /home/class/SoftDev/ folder
  2. Copy the directory to your folder: cp -r namesclientserver ~
  3. Go to your folder cd ~
  4. Go to the new project folder: cd namesclientserver

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 name_stats_ajax.html change the line:

     XMLHttp.open("GET", "/cgi-bin/skon_namefetchajax.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

In fifo.h change line 33:

const string SIG = "Skon_";

So that Skon is changed to you 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
  3. Go to your folder with a browser, and open name_stats_ajax.html

Create a new project

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

cd ~
cp -r namesclientserver shakeproject

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

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.

Shakespeare Program

In project 1 you created code to lookup words in Shakespeare. You will combine that code with the code from this US Name data system to make a web version of your Shakespeare 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 Shakespeare 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 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 ./shakeserver &

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.

Requirement Data Structures Intro Prog Comments Score
Program displays matching lines for each word entered on the web page* 40 50    
Well designed User Interface* 20 20    
Program broken up into functionally cohesive functions* 10 20    
Program has meaningful comments, good variable names, and good formatting* 10 10    
Program uses appropriate classes 10 10    
Program highlights the words as bold in the output. 10 10    
Program allows the searching for two words on the same line. 10 20    
Program shows book that each match is found in (show book name only once per book) 10 20    
*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 ./shakespeareserver &" 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.
Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng NamesWebArchtecture.png r3 r2 r1 manage 57.9 K 2017-01-26 - 04:36 JimSkon  
PNGpng Screen_Shot_2017-01-26_at_9.14.36_AM.png r1 manage 310.4 K 2017-01-26 - 14:16 JimSkon  
GIFgif shake.gif r1 manage 36.6 K 2017-01-26 - 14:16 JimSkon  
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2017-03-01 - 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