Question: Write a program that provides a sequential server listening for connections on a port which is specified as the only cmd-line argument. The server should

Write a program that provides a sequential server listening for connections on a port which is specified as the only cmd-line argument. The server should sequentially handle one client at a time.

The server should receive messages from clients of this form: put key val get key

The server should print each command that it receives.

For put commands, the server should store the key and associated value as character strings. You may assume that no key or value will be more than 32 bytes. The value of a key put by one client may be used in a get command by some subsequent client. The server should print a message for each get command:

key val ## where key and val are replaced by the appropriate values

To test, I will run your server this way: ./p5 NNNN ## where NNNN is some port number that I will choose at run time

Then, in a separate window, I will run a client something like this: nc -q 1 -i 2 system64 NNNN < some_input_file

Your code should operate and print correctly whether or not a received message contains a newline character, or a null terminator character, or neither.

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!