Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

client.py from socket import * from bitstring import* import time # function to initiate the file transfer along with acknowledgments and packet loss def Make_Packet(buf):

client.py

from socket import *

from bitstring import*

import time

# function to initiate the file transfer along with acknowledgments and packet loss

def Make_Packet(buf):

seq = 1

# reading file packets from the directory

data = f.read (buf)

while (data) :

# sending packets to the specified address

if (s.sendto (data , addr)) :

print ("Packet Sent")

data = f.read (buf)

print (" data type ",type(data))

seqq = str(seq)

# sending the sequence number regarding the packet

s.sendto (seqq.encode() , addr)

# receiving the ACK from the server

ACK, pat = s.recvfrom (200)

print ("Status : "+ ACK.strip().decode())

seq=seq+1

if (seq>=5 and seq%2==0):

data =" "

data = bytes (data , 'utf-8')

print (" ---data type " , type (data))

s = socket(AF_INET,SOCK_DGRAM)

host ="127.0.0.1"

port = 9999

buf =1024

# setting the address to the server machine

addr = (host,port)

file_name="file.bmp"

# sending the filename

s.sendto(file_name.encode(),addr)

f=open(file_name,"rb")

# calling function to perform file transfer

Make_Packet(buf)

s.close()

f.close()

server.py

from socket import *

import sys

# setting hostname and the port number

host="127.0.0.1"

port = 9999

# creating socket object

s = socket(AF_INET,SOCK_DGRAM)

# binding the socket with address

s.bind((host,port))

addr = (host,port)

buf=1024

# recieving the filename from the client

data,addr = s.recvfrom(buf)

print ("Received File:",data.strip())

filename = "server_"+data.strip().decode()

print ("Received File DECODED:",filename, type(filename))

# opening blank file with recieved name

f = open(filename,'wb')

# recieving data packets

data,addr = s.recvfrom(buf)

try:

num=1

while(data):

# writing data to the blank file

f.write(data)

# setting timeout of the file

s.settimeout(2)

# getting sequence numbe from the client reagarding recieved packet

seq,addr = s.recvfrom(10)

sequence = seq.strip().decode()

# comparing the packet and the sequence number, if as per expectations

if (sequence==str(num) and len(data)==1024):

print ("Packet Sequence : ", sequence ,"---Recieved Sequence : ", num,"---Bits Recieved : ",len(data))

print ("Packet Acknowledged")

ACK = "Regular Packet SEQ # "+ sequence+ " ACK from Server with "+ str(len(data))+" bits"

# sending the acknowledgment back to client regarding packet sequence and bits recieved

s.sendto( ACK.encode ( ) , addr)

# checking if disturbed/dropped packet recieved

elif (sequence==str(num) and len(data)!=1024):

print ("- - - - - PACKET Dropped - Sequence Disturbed - - - -- - ", 1024-len(data))

ACK = "Dropped Packet SEQ # "+ sequence+ " ACK from Server with "+ str(len(data))+" bits"

# sending the acknowledgment back to client regarding packet sequence and bits recieved

s.sendto( ACK.encode ( ) , addr)

else:

print ("PACKET Dropped - Sequence Disturbed")

ACK = "Packet Dropped, Not Recieived"

# Sending acknowledgment if packet not recieved as per the expectations

s.sendto( ACK.encode ( ) , addr)

# recieving the next packet

data,addr = s.recvfrom(buf)

num=num+1

except timeout:

f.close()

s.close()

print ("File Downloaded")

( can you add thisfunction which is below and give a correct output which is similar to the below I tried much, can you help as soon as because I need two hours.)

Server:

recv_pkt comp_checksum is_corrupt - Parikshit has_seq0 extract_bits make_pkt udt_send corrupting - Parikshit

Client: make_pkt recv_pkt comp_checksum is_corrupt -Parikshit is_ACK udt_send

image text in transcribed
server.py Phase_3_server X phase_3_client X C: \\Users\\mspat\\PycharmProjects\\PHASE_3\\Scripts\\python. exe C: /Users/mspat/PycharmProjects/PHASE_3/Phase_3_server . py Enter A Whole Number Between 0 and 100 For Data Corruption Chance 0 The server is ready to receive Image received Process finished with exit code 0 client.py Phase_3_server X phase_3_client X C: \\Users\\mspat\\PycharmProjects\\PHASE_3\\Scripts\\python. exe C: /Users/mspat/PycharmProjects/PHASE_3/phase_3_client . py Enter A Whole Number Between 0 and 100 for ACK Corruption Chance Image transmitted successfully. 1408 packets were transmitted. Transmission time: 0. 8053237000000006 seconds Closing client program. Process finished with exit code 0

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

Step: 3

blur-text-image

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