Question

Write TCP client and server programs in Python that the client gets a set of integers...

Write TCP client and server programs in Python that the client gets a set of integers and the length of the set as command line arguments. Then the client sends the set to the server. Afterward, the server computes the total, the highest number, the lowest number, and the mean (in float) of the set and sends the results to the client. Finally, the client receives the results and prints them out.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Tcp client and server Python 3 code are given below. Make sure you are using python 3 and use proper indentation

In TCP client first enter siz of list then enter the numbers of list.

First start server in command line then in another command line start client with arguments

*************************tcpClient.py*********************************

import sys
import socket

argc=len(sys.argv)

if argc<2 or argc!=int(sys.argv[1])+2:
print('Insufficient arguments');
sys.exit()
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_address=('127.0.0.1',9876)
num=int(sys.argv[1]);
send_str=''
for i in range(2,num+2):
send_str=send_str+' '+sys.argv[i]
  
print(send_str)

sock.connect(server_address)
sock.send(send_str.encode())
data=sock.recv(1024)
print('Received Message From Server is:')


print(data)

*************************tcpServer.py***********************************

import socket

def findMinMax(list):
max=list[0]
min=list[0]
for i in range(len(list)):
if list[i]>max:
max=list[i]
if list[i]<min:
min=list[i]
return min,max
def findTotalAndAvg(list):
sum=0
for i in range(len(list)):
sum=sum+list[i]
avg=sum/len(list)
return sum,avg

sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip='127.0.0.1'
port=9876

sock.bind((ip,port))
sock.listen(5)
print('Server started at '+ip+','+str(port))

while 1:
conn, addr = sock.accept()
arr=[]
message= conn.recv(1024)
if message:
message=str(message,encoding='utf_8')
#print('Received from client:'+message)
  
arr=message.split()
arr = list(map(int, arr))
  
min,max=findMinMax(arr)
sum,avg=findTotalAndAvg(arr)
  
send_msg='Minimum='+str(min)+' Maximum='+str(max)
send_msg=send_msg+' Total='+str(sum)+' Average='+str(avg)
print(send_msg)
conn.send(send_msg.encode())
sock.close()
  

Add a comment
Know the answer?
Add Answer to:
Write TCP client and server programs in Python that the client gets a set of integers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or...

    Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or UDP Protocol, the application should do the following: 1. Client reads a line of characters (data) from its keyboard and sends data to server 2. Server receives the data and converts characters to uppercase 3. Server sends modified data to client 4. Client receives modified data and displays line on its screen

  • Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array...

    Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array of struct student_info ( char abc123171 char name [101 double GPA; To simplify the tasks, the server should create a static array of 10 students with random abc123, name, and GPA in the server program. Then the server waits for clients. When a client...

  • Write two programs Client and Server

    Given two integer matrices A and B, you are requested to compose a program to perform matrix addition (A + B). Both matrices have N rows and M columns; N > 1, M > 1; You need to divide both (A and B) into four equal (or close to equal) size of submatrices (A0,0, A0,1, A1,0, A1,1 and B0,0, B0,1, B1.0, B1.1)andeachsubmatrixhasdimensioncloseto(N/2)x(M/2). YouneedtocreatefourJavathreads each thread performs a subset of addition on one pair of the submatrices. Example, thread 0 performs addition...

  • Using network sockets, write a C program called client that receives three command-line arguments in the...

    Using network sockets, write a C program called client that receives three command-line arguments in the form: client host port file and sends a request to a web server. The command-line arguments are hostRepresents the web server to connect to port Represents the port number where a request is sent. Normally an HTTP request is sent over port 80, but this format allows for custom ports file Represents the file requested from the web server Your program should create a...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • Assignment One program will be the update server and the other will be the update client....

    Assignment One program will be the update server and the other will be the update client. Here is how the two programs should interact with each other: Server 1. the server starts up and reads the version number in the data.bin file and stores it in memory. 2. The server binds to a port and awaits connections. Client 1. The client starts up and it will first read the version number found within it's own data.bin file. 2. The client...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • Your task is to write a C++ program that consumes integer values as command line arguments...

    Your task is to write a C++ program that consumes integer values as command line arguments and returns the arithmetic mean of these values. To increase the flexibility of the program, there should be no set number of arguments. To overcome this, we will require the argument argv[1] to be the number of integers the user enters. For example, if the user wants to calculate the arithmetic mean of 4 numbers, they would pass in 4 as the first argument...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a...

    PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a Python program that displays and describes the equation for plotting the sine function, then prompts the user for the values A, B, C and D to be used in the calculation. Your program should then compute and display the values for Amplitude, Range, Frequency, Phase and Offset. Example input/output for part 1: Part 2: Displaying a Vertical Plot Header A vertical plot of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT