Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the Server code written in Python for the given client code. A sample working client code is given to you in Client.py. I

I need the Server code written in Python for the given client code.

A sample working client code is given to you in Client.py. I need a corresponding Server code. The goal of the server is to get any string sent to it, and switch any letters from lower case to capital and vice-versa. There will be checksuming. This means that you must compute the internet checksum, the inverse of the 16 bit 1's compliment sum, and prepend it to each message sent.

NOTE: when computing the checksum, two zero bytes should be attached to the beginning of the message.

Whenever a message is sent, the two byte checksum should be attached to the beginning like this:

message = b'blahblah' checksum(b'\0\0blahblah') == b'xV' s.sendall(b'xVblahblah')

Where, in this case xV is the proper checksum. Whenever a message is received, the checksum should also be computed.

Instead of responding with the case inversed message, simply respond ERROR if the checksum is incorrect.

When responding ERROR, leave the checksum field as zero to distinguish it from the correct response to b'error'

NOTE: not all checksums will be ASCII characters and they may appear strange when viewed with a file editor or printed on the terminal.

The client code is provided below:

import argparse

from sys import argv

import socket

#First we use the argparse package to parse the aruments

parser=argparse.ArgumentParser(description="""This is a very basic client program""")

parser.add_argument('-f', type=str, help='This is the source file for the strings to reverse', default='source_strings.txt',action='store', dest='in_file')

parser.add_argument('-o', type=str, help='This is the destination file for the reversed strings', default='results.txt',action='store', dest='out_file')

parser.add_argument('server_location', type=str, help='This is the domain name or ip address of the server',action='store')

parser.add_argument('port', type=int, help='This is the port to connect to the server on',action='store')

args = parser.parse_args(argv[1:])

#next we form a client socket

client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_addr = (args.server_location, args.port)

client_sock.connect(server_addr)

#now we need to open both files

with open(args.out_file, 'wb') as write_file:

for line in open(args.in_file, 'rb'):

#now we write whatever the server tells us to the out_file

client_sock.sendall(line)

answer = client_sock.recv(512)

write_file.write(answer)

#close the socket (note this will be visible to the other side)

client_sock.close()

The program should work with the following type of example for command lines:

python Server.py PORT python Client.py SERVER_ADDRESS PORT

An example of this would be: python Server.py 5444 python Client.py ram.cs.university.edu 5444

Some output pictures would be appreciated to make sure that the code works properly. Thank You.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

2. How do these two kinds of buyers differ in mo- tivation?

Answered: 1 week ago