Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this week, you will be creating two small Python3 programs that will communicate over a TCP/IP socket. This exercise will help illustrate one way

For this week, you will be creating two small Python3 programs that will communicate over a TCP/IP socket. This exercise will help illustrate one way for two different processes to communicate with each other.

The first python program should be called upper_server.py. This program will act as a server, binding to a port on your computer and waiting for socket clients to connect. When a client connects, the upper_server.py program will wait until the client sends a message. Each message will be ASCII based and delimited by a newline. For each message received, the upper_server.py program will convert the contents into the designated case and send the response back to the client, with each message terminated again by a newline. The upper_server.py program should accept a --port command line parameter, indicating what port the program should listen on for clients. By default, upper_server.py should convert any incoming text to lower case before echoing back to the client. If the program receives the text 'UPPER' (case-insensitive), then it should upper case the contents of any echo'd content. The incoming string 'lower' (case-insensitive) should revert back to subsequent output to lower case. Make sure to echo back the commands 'UPPER' and 'LOWER' back to the client, with the appropriate case changes.

The second python program should be called upper_client.py. This program will connect to localhost (which is your computer) and to a specified port. Once connected to the server, it will request the user for input. Whatever input the user enters (terminated by hitting the ENTER key) will be sent to the upper_server.py program over the socket. Each response from the upper_server.py program will be printed out to the screen, then the upper_client.py program will accept additional user input. The upper_client.py program continue performing the cycle of request input, send to server, print response until the program is terminated. The upper_client.py program should also accept a --port command line parameter, indicating what port it should try to connect to.

Both programs should use the socket and argparse modules that come included with Python.

Each program should be started in separate terminal windows, with the upper_server.py program started first. Both programs should run until the user terminates the program (i.e. hitting CTRL-C on a Mac).

Below are sample outputs from each program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions