Question: Python makes the storing of key-value pairs very easy with the dictionary. Your program should essentially create the socket, continuously loop while checking for request,

Python makes the storing of key-value pairs very easy with the dictionary. Your program should essentially create the socket, continuously loop while checking for request, parse any incoming requests, and perform the appropriate action. Need help filling out skeleton below .

import socket

dictionary = {} # Dictionary that will hold the key-value pairs

# HTTP return messages HTTP = 'HTTP/1.1 ' OK = HTTP + '200 OK' UNSUPPORTED = HTTP + '220 UNSUPPORTED' BAD_REQUEST = HTTP + '400 BAD_REQUEST' NOT_FOUND = HTTP + '404 NOT FOUND'

# Implement the get function that returns the value for the specific key from the dictionary def get(...):

# Implement the put function that updates the value for the specific key in the dictionary def put(...):

# Implement the delete function that will remove the key-value pair from the dictionary def delete(...):

# Implement the delete function that will remove all the key-value pairs from the dictionary def clear(...):

# Implement the quit function that will end the connection with the client def quit(...):

# Implement the main function where we create, bind and listen to a socket. When a client is connection receive the # message, decode the command and call the corresponding function. Server should send an answer to the client's request. # When client closes the connection(quit) server should also close the connection. Bind your server to IP '0.0.0.0' so that # it will listen to local connection requests. def main(): # You can use this operations dictionary to get the corresponding function: For example $func = operations['get'](params) is equal to $get(params) operations = {'get': get, 'put': put, 'delete': delete, 'clear': clear, 'quit': quit} ...

if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!