Question: i need help with a PYTHON 3 program. the program runs using common line arguements, for example client.py is run by client.py 127.0.0.1 3126 7

i need help with a PYTHON 3 program. the program runs using common line arguements, for example client.py is run by

client.py 127.0.0.1 3126 7

server.py 127.0.0.1 3126

*********************************************************************************************************

#! /usr/bin/env python3

# Echo Client

import sys

import socket

# Get the server hostname, port and data length as command line arguments

host = sys.argv[1]

port = int(sys.argv[2])

count = int(sys.argv[3])

data = 'X' * count # Initialize data to be sent

# Create UDP client socket. Note the use of SOCK_DGRAM

clientsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Send data to server

print("Sending data to " + host + ", " + str(port) + ": " + data)

clientsocket.sendto(data.encode(),(host, port))

# Receive the server response

dataEcho, address = clientsocket.recvfrom(count)

print("Receive data from " + address[0] + ", " + str(address[1]) + ": " +

dataEcho.decode())

#Close the client socket

clientsocket.close()

******************************************************************************************************************************************

#! /usr/bin/env python3

# Echo Server

import sys

import socket

# Read server IP address and port from command-line arguments

serverIP = sys.argv[1]

serverPort = int(sys.argv[2])

# Create a UDP socket. Notice the use of SOCK_DGRAM for UDP packets

serverSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Assign server IP address and port number to socket

serverSocket.bind((serverIP, serverPort))

print("The server is ready to receive on port: " + str(serverPort) + " ")

# loop forever listening for incoming UDP messages

while True:

# Receive and print the client data from "data" socket

data, address = serverSocket.recvfrom(1024)

print("Receive data from client " + address[0] + ", " + str(address[1]) + ": "

+ data.decode())

# Echo back to client

print("Sending data to client " + address[0] + ", " + str(address[1]) + ": "

+ data.decode())

serverSocket.sendto(data,address)

************************************************************************************************************************************

most of the modifcation should be in the client.py file. Using the settimeout(value) function. i want client to try to send a message three times. and if the server doesn't reply all three times i want a message to print. below you can find the print statement thats should happen.

i need help with a PYTHON 3 program. the program runs using

Example of the client trace output (server responds): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Receive data from 127.0.0.1, 12000: XXXXXXXXXX Example of the client trace output (server does not respond): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Message timed out Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Message timed out Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Message timed out

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!