ORT BRAUDE COLLEGE OF ENGINEERING Electronic and Electrical Engineering Department Client Server Systems 31261 PROJECT 8: DBM Client/Server * You must submit project 8 (Chat client/server that was planned earlier has been cancelled) * Work in pairs is OK. * Due date is: Thursday, July 18, 2013 See below how to submit the project * According to the course program, projects are mandatory, and will form an integral part of the course grade (30%) * You have to complete the design of three classes in this project: DBMserver, ResponseThread, DBMclient Most of the code has been written and is provided to you in this zip bundle: http://tinyurl.com/samyz/cliserv/projects/proj8.zip Your task is to complete the missing links and small pieces of code to make it work. The precise requirements and characterization is specified in the following description. * Make sure to include a documentation before each class and each method that clearly states what you are trying to do. Please be short and precise. * IMPORTANT: Please stick to the required names of classes, methods, and functions !!! Do not invent your own names or try to modify the names in any way !!! Your work will be checked and graded by automatic scripts on top of your code. So if you do not use the correct names for classes, methods, and functions, you may loose valuable points for your grade! * How to submit your work? You should send your work to: samyz.ort.braude@gmail.com as one zip file: proj8.zip The zip file should contain: proj8/README.txt proj8/db_manager.py proj8/dbm_manager.py proj8/dbm_client.py proj8/dbm_shell.py proj8/filters.py proj8/test.py proj8/socket_utils.py README.txt: This file should contain your names (one or two partners), course name, id, email, and phones, and any other special information or comments that you think ought to be there. test.py: This file should include all your tests of the classes and functions in the file proj4.py This file is not going to be checked ar graded, but it maybe needed for reference on how you are using your classes and functions. * Please report any error or missing items in this assignment to me. It may be updated several times, so do not save a copy and rely on it. You are encouraged and welcome to submit any errors or comments to: samyz.ort.braude@gmail.com Please ask any question that bothers you and report anything which is not completely clear. Just state the line number in this file and what is the error or unclear part. * Make sure to insert clear and short comments that explain what you do. * Use consistent coding style. Make sure your code is short, clear, and readable ! * Except for accuracy and code correctness, your code will also be checked and credited according to readabilty, simplicity, function length, run time, efficiency, and beauty! - Bad function or variable names are against Python philosophy! - Complicated and very long lines or paragraphs are a clear indication of design problems! --------------------------- DBM PROTOCOL SPECIFICATION --------------------------- Command argument notation: Mandatory argument (must be supplied or an error is issued) [arg] Optional argument. If not supplied, a default value is taken (depending on the command) --------------- CLIENT COMMANDS --------------- KEYS Get the database keys from the server SIZE Server should return size of its database. That is, the number of database records it holds in memory Example: >> SIZE => 8828 RECORD n [keys] Get record number n from the server in a formatted way. Example: >> RECORD 17 => Gender = female Title = Ms. GivenName = Cindy Surname = Roy StreetAddress = 4925 Duck Creek Road City = San Francisco State = CA ZipCode = 94104 ... = ... FILTERS Send a filters file from a DBM client to the DBM server to current directory in client. An example of a filters file is given inside this directory: filters.py - mandatory argument can be an absolute file path like: "c:/braude/proj8/filters.py" or a relative file path like "bar/filters.py" or simply "filters.py". In case of a relative path, then it is relative to the current working directory of the client Examples: FILTERS filters.py FILTERS bar/filters.py FILTERS c:/braude/proj8/filters.py Note that you have to send this file from the client to the server. Therefore the server must save it under its working directory and associate it with the specific client. To make sure that two clients do not step on each other, the server must save the filters file under a unique name (socket port number?) QUERY [keys] The server should return all records that pass the . [keys] is an optional argument for specifying which keys ("columns") should be included in each record. If keys is not provided then it defaults to all keys. Examples: >> QUERY filter1 GivenName City State => Jessica,San Francisco,CA William,San Francisco,CA Doris,San Francisco,CA ...... and so on ..... >> QUERY filter3 => female,Ms.,Jessica,Falls,1904 Green Avenue,San Francisco,CA,94107,United States,JessicaJFalls@teleworm.us,510-844-1443,Hopkins,3/30/1976,546-94-4569,1Z 6A8 185 02 2522 028 2,Textile presser,Franklin Simon,2005 Ferrari F430,OpportunityHappens.com,A+,137.3,62.4,5' 7",169,56cd5fbb-bebb-4ee0-b5cc-927637b1e031,37.724434,-122.388579 male,Mr.,Gary,Austin,3816 Murry Street,Virginia Beach,VA,23464,United States,GaryAAustin@dayrep.com,757-424-1695,Green,2/17/1993,228-58-3162,1Z 459 355 86 8537 461 8,Coil taper,Pioneer Chicken,1994 Daihatsu Domino,LocalAvenues.com,A+,194.5,88.4,6' 3",190,d4170037-5dec-4385-904e-48fd82d95131,36.744548,-76.093242 female,Dr.,Kathy,Kuntz,2928 Walt Nuzum Farm Road,Rochester,NY,14608,United States,KathyIKuntz@gustr.com,585-503-6578,Burchard,1/30/1983,113-09-4378,1Z 339 961 50 8010 782 0,Drilling and boring machine tool setter,Realty Solution,2010 Jeep Liberty,TaxExpo.com,A+,144.8,65.8,5' 7",170,95023081-13fc-4269-bafb-d5a46498834c,43.150427,-77.624216 >> QUERY filter3 Gender GivenName City BloodType => female,Jessica,San Francisco,A+ male,Gary,Virginia Beach,B+ female,Kathy,Rochester,B- ...... and so on ..... QUIT Signal end of session (Disconnect) from the DBM session -------------------------- SERVER RETURN STATUS CODES -------------------------- WARNING: This is just an initial suggestion! The precise specification should be decided by your implementation. Feel free to change and add status numbers if your solutions need them, but make sure to document all the details so your work can be checked correctly. 200 Authentication successful fulfilled (Not implemented) 201 KEYS request OK: sending keys 202 SIZE Request OK: sending size 203 RECORD request OK: sending record 204 FILTERS request OK: saving filters file at server storage 205 QUERY request OK: sending records 206 QUIT request OK: closing connection. BYE. 400 Bad request 401 Invalid record number 402 Incomplete QUERY request 403 Invalid key name 404 Invalid filter name 411 Authentication failed (not implemented) 500 Server Error ------------------------------------- API - APPLICATION PROGRAM INTERFACE ------------------------------------- Your work: ---------- All the instructions and suggestion on how to implement the three classes are included inside the files: dbm_serverl.py, dbm_client.py, dbm_shell.py Please edit these files and follow the instructions in comments ----------------- USE CASE EXAMPLES ----------------- How you should use your classes? The following examples show how your code should work. 1. It should be easy for you to create three different file servers that work in parallel on the same host! 2. Similarly, it will be easy to create several clients and make them work simultaneously DBM SERVER: # Start DBM server at host: shark.braude.ac.il ! serv1 = DBMserver("table1.csv", 12345) # Server should start right away ... # After 5 hours ... we close servers 1 serv1.close() DBM CLIENT: # Start three DBM clients from a different host client1 = DBMclient("shark.braude.ac.il", 12345) client2 = DBMclient("shark.braude.ac.il", 12345) client3 = DBMclient("shark.braude.ac.il", 12345) # Note that clients 1, 2, 3 are connected to serv1, client1.send("SIZE") client1.send("KEYS") client1.send("FILTERS c:/workspace/filters.py") client1.send("QUERY filter17") client1.send("QUIT") client1.close() --------------------- Your work: DBM SHELL --------------------- You need to implement a DBM Shell! A DBM is a command line application similar to cmd.exe in which you connect to a DBM server and can run a CLIENT DBM commands from the shell. The DBM shell should be implemented in the file: dbm_shell.py It should work as follows: 1. Start a DBM server on a cmd.exe window 2. Start a new cmd.exe window 3. Enter your work directory 4. Run the command: dbm_shell.py 5. You should be able to interact with the DBM server as follows: >> SIZE 202 SIZE Request OK: sending size 8087 >> FILTERS my_filters.py 203 FILTERS request OK: saving filters file at server storage >> QUERY filter1 GivenName City State Jessica,San Francisco,CA William,San Francisco,CA Doris,San Francisco,CA ...... and so on ..... >> QUIT 205 QUIT request OK: closing connection. BYE. Start with the file: dbm_shell.py It should guide you in how to start ----------------------- HOW TO TEST YOUR CODE ? ----------------------- To test your code efficiently we suggest that you create 3 additional Python files in the same directory where you work: File 1: run_server.py ------------------ from dbm_server import * server = DBMserver("table1.csv", 12345) Flie 2: run_client.py ------------------ from dbm_client import * client = DBMclient("localhost", 12345) status = client.send("SIZE") print status status = client.send("KEYS") print status status = client.send("FILTERS filters.py") print status status = client.send("QUERY filter1 GivenName City State") print status status = client.send("QUIT") print status client.close() Running these programs ---------------------------- 1. Open a cmd.exe console, and run the command: > run_server.py 2. Open a second cmd.exe console, and run the command: > run_client.py - You should be able to see the prints you made in run_client.py - Make sure to check that you can really handle multiple clients simultaneously! - You can start more cmd.exe consoles and run more clients from them ... 3. Open a third cmd.exe console, and run the command: > dbm_shell.py You should be able to communicate with the server that you started in stage 1