关键词 > Python代写

Project 1: A Simple KeyValue Service

发布时间:2022-02-15

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Project 1: A Simple KeyValue Service

Project Description

This project is designed to familiarize you with socket programming to implement      simple network functions. You will develop a client program and a server program     that communicate with each other using TCP sockets . The server process hosts a key- value store that clients can interact with. Specific interactions include the following:   storing key/value pairs into the store, retrieving key/value pairs from the store, listing the key set and list the value set .

Language

You can write your code in whatever language you choose, as long as your code       compiles and runs on Linux machines1 on the command line. Do not use libraries   that are not installed by default in Linux . Similarly, your code must compile and  run on the command line. You may use IDEs (e.g. Eclipse) during development, but do not turn in your IDE project without a README file and/or a Makefile .       Make sure you code has no dependencies on your IDE.

Key-Value Store

A key-value store is essentially a database that maps keys to their corresponding         values. In this project, you will implement a simplified key-value store. Each item in  the key-value store has a key, which is the name of the item, and a value, which is the actual content of the item . A key-value store provides the following basic functions:

Function

Description

get(key)

gets the value of the corresponding key from the key-value store

put (key,

value)

updates the value of the corresponding key in the key-value store

or

create a new pair of key-value in the key-value store if the key doesn’t currently exist

mappings

retrieve all the key-value pairs from the key-value store

keyset

retrieve all the keys from the key-value store

values

retrieve all the values from the key-value store

In addition to the above functions, the service also provides two auxiliary functions:

help and bye. The function help allows clients to list all the available functions provided by the server. The function bye terminates the client process.

Client-Server Interactions

The client program can interact with the server from command line interfaces. The server process should be started in the terminal first . For example:

Throughout this instruction, Python is usedfor demonstration purpose. But specific

We can assume that this service is running on a fixed port number, e.g. 50000, that is known by the client. Then the client program should be invoked in another terminal   window as follows.

Upon starting, it prints a welcome message:

After this, the client program asks for the IP address or hostname of the server that user should type in. If the IP address or hostname is valid, the client should see the following messages:

Once a connection is established, the client should receive a welcoming message from the server and prints it on the screen. Meanwhile, a prompt will show up for the user    to enter commands.

All user commands are entered on a single line. The client stays in a loop reading a     command typed by the user, sending the command to the server, and reading and        displaying the response. The client terminates after it receives bye command from the

user.

Following is a sample interaction between the client and the server, as seen from the client’s side:

python client.py

 

 

 

 

 

 

 

 

 

 

 

 

KeyValue Service> mappings

a 1

aaa a 4

b 2

KeyValue Service> put aaa   a 5

Ok.

KeyValue Service> mappings

a 1

aaa a 5

b 2

A few notes for implementing the programs:

§ You should always check the validity of user input , such as IP addresses and   commands. This can be done either on the client side or on the server side . An example of invalid commands are following:

§ You should also check the correctness of command format. For example, the     get function needs to have a parameter that represents key and the put       function should contain key and value parameters2 . Note that the key parameter may include multiple while spaces in between , but you should compress            multiple white spaces into a single one when being stored in the key-value         store. Invalid command format includes the following:

KeyValue Service> get

 

KeyValue Service> put aaa a

 

KeyValue Service> put a

§ The server should handle errors and exceptions properly. For example, if user tries to retrieve a key that doesn’t exist in the data store, the server should       return appropriate messages such as:

§ The server should be able to serve multiple clients at the same time. To achieve this, you can use multithreading or multiprocessing techniques we discussed in  class.

VM Setup

If you need a Linux environment to test your codes, you can set up a VM on your laptop as follows.

Install Ubuntu VM on Mac with M1 chip

https://mac.getutm.app/gallery/ubuntu-20-04

The above link contains the instructions on installing VMs with UTM if you are using Mac with M1 chip.

Install Ubuntu VM on other platforms

Download and install VirtualBox , a virtualization platform and download the VM Image .

Import the image to VirtualBox - in the File menu, select Import Appliance .             A user named “eecs325” has been created. You can login with password “networks”. You can also access the VM from your host terminal with the following command:

REMINDERS

o To turn in your project, you should submit the following files:

§ A Makefile that compiles your code if available

§ A plain-text (no Word or PDF) README file. In this file, you should  briefly describe your high-level approach and an overview of how you tested your code.

o Your README, Makefile, source code, etc. should all be placed in a directory. Submit your code to Canvas in a zip file .

o If your code does not compile or could not run , you will not get credits.

o All student code will be scanned by plagiarism detection software to ensure that students are not copying code from the Internet or each other. We will

randomly check student's code to make sure that it works correctly.

o Document your code (by inserting comments in your code)