Question

In: Computer Science

Python Programming I have a skeleton code here for this project but do not know exactly...

Python Programming

I have a skeleton code here for this project but do not know exactly where to start. My task is to implement a reliable File Transfer Protocol (FTP) service over UDP. I need help to write the reliable FTP client and server programs based on an Alternating Bit Protocol (ABP) that will communicate with a specially designated server. In socket-level programming as well...

# program description

# Library imports

from socket import *

import sys

import time

# Variable declarations

server = "harp.ece.vt.edu" # server

tcpPort = 21000 # TCP listening port

buffer = 4096 # defines the size of acceptable data for receipt

message ="debug" # controls condition of transfered data. debug: no delay or corruption

# normal: server introduces delays and errors into transmission

# Initialize variables

# sequence number value 1

# sequence number value 0

# Temporary variable for alternating sequence numbers

# control value transfer in progress

# initial setting is for ACK1 but changes during execution

# calculated by a char by char ordinal sum of the packet

# value is then converted to 4-digit ASCII value via

# sum mod 10000

PAYLOAD = ""

udpPort = 0 # variable to hold udpPort number

completeFile = [] # accumulation of complete file transfer

serverResponse = "" # server response variable

endFile = False # flag for end of transmission

badPacket = False #flag for bad checksum comparison

# Create socket variable

sTCP = socket(AF_INET, SOCK_STREAM) # TCP socket definition

sUDP = socket(AF_INET, SOCK_DGRAM)  # UDP socket definition

# send ACK packet to server

Some further instructions include:

The four fields of the “RFP” protocol are:

● SEQUENCE: This is the sequence number of the packet, and can legally assume either of the two values: “0000” or “0001”.

● CHECKSUM: This is a 4-digit ASCII number that is the byte-by-byte sum, modulo-10000, of all data in the payload including the header SEQUENCE and header CONTROL.

● CONTROL: Used by the server to indicate Transfer in Progress “0000” or All Done “0001”. The client should set this field to “0000”. “0002” is reserved for future use.

● DATA: Used by the server to send part of the data file it is transferring

We will establish a “channel”  here, the server will respond with a unique UDP port for you to use for your file transfer: 1. Open a TCP connection to harp.ece.vt.edu over port 21000 2. Send the word “normal” to the server over this port. 3. The server will respond with a number formed in an ASCII string. This is the UDP port that you shall use in the file transfer session. 4. Close the TCP connection. Once you have been assigned a UDP port, you are ready to start the file transfer after you open the socket.

To initiate the file transfer, the client should send an ACK1 packet (sequence number = “0001”, control = “0000”, a computed checksum, and zero bytes of data). As stated above, the checksum is the character-by-character ordinal sum over the entire packet (excluding the checksum field). For the ACK1 packet, checksum = “0”+”0”+“0”+”1”+“0”+”0”+“0”+”0” = ASCII 48 + 48 + 48 + 49 +48 + 48 + 48 + 48 = 385. The 4-digit modulo-10000 ASCII decimal equivalent of this checksum is “0385.” 1 The server will then start sequentially sending the file data, starting with a packet with Sequence Number 0. Abide by the Alternating Bit Protocol to transfer the contents of the file. When the server has completed the file transfer, it will send a final packet with no data with the control field set to “0001.” You must ACK this packet. Then you can close your UDP session and save the output file.

Since the file will be larger than a single packet, the server will segment the file into chunks that will fit within packets. The client will need to reassemble these and put them in a file called reliable.txt.

8.5.2

Solutions

Expert Solution

sender.py

#!/usr/bin/env python

from socket import *
import sys

s = socket(AF_INET,SOCK_DGRAM)
host =sys.argv[1]
port = 9999
buf =1024
addr = (host,port)

file_name=sys.argv[2]

f=open(file_name,"rb") 
data = f.read(buf)

s.sendto(file_name,addr)
s.sendto(data,addr)
while (data):
    if(s.sendto(data,addr)):
        print "sending ..."
        data = f.read(buf)
s.close()
f.close()

receiver.py

#!/usr/bin/env python

from socket import *
import sys
import select

host="0.0.0.0"
port = 9999
s = socket(AF_INET,SOCK_DGRAM)
s.bind((host,port))

addr = (host,port)
buf=1024

f = open("file.pdf",'wb')

data,addr = s.recvfrom(buf)
try:
    while(data):
        f.write(data)
        s.settimeout(2)
        data,addr = s.recvfrom(buf)
except timeout:
    f.close()
    s.close()
    print "File Donwloaded"

note: plzzz don't give dislike.....plzzz comment if you have any problem i will try to solve your problem.....plzzz give thumbs up i am in need....


Related Solutions

hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton...
Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton of the program, and the input and output. # Initialize list mylist = [ ] # Set up loop to put menu on screen num = 1 while num != 0:      print(" ")     print(" ")     print("            Menu ")      print ("0 - Quit")     print ("1 - Add item to list")     print ("2 - Pop item off list and print...
I know how to do this with arrays, but I have trouble moving my code to...
I know how to do this with arrays, but I have trouble moving my code to use with linked lists Write a C program that will deal with reservations for a single night in a hotel with 3 rooms, numbered 1 to 3. It must use an infinite loop to read commands from the keyboard and quit the program (return) when a quit command is entered. Use a switch statement to choose the code to execute for a valid command....
What do you know about programming in Python? What is the difference between Python and Java?
What do you know about programming in Python? What is the difference between Python and Java? What does the term Open Source mean? Name four examples of Open Source software. What is the IDEL programming environment? How does IDEL relate to Python? How do you spread a long statement over multiple lines in Python? How do you use the loop-index? How will knowing and understanding Python impact what you do in your profession and/or personal experiences?
I am new to socket programming and I wish to know what these lines of code...
I am new to socket programming and I wish to know what these lines of code do. I know they are creating UDP sockets, but it would help if someone explained what the code means. Thank you. Python Code: import socket testingSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) testingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, testingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) testingSocket.bind(('0.0.0.0', 50000)) send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) send_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) receiving_thread = Thread(target=self.receivingFunction) send_thread = Thread(target=self.sendMessage) broadcast_online_status_thread = Thread(target=onlineStatus)
Python I am creating a class in python. Here is my code below: import csv import...
Python I am creating a class in python. Here is my code below: import csv import json population = list() with open('PopChange.csv', 'r') as p: reader = csv.reader(p) next(reader) for line in reader: population.append(obj.POP(line)) population.append(obj.POP(line)) class POP: """ Extract the data """ def __init__(self, line): self.data = line # get elements self.id = self.data[0].strip() self.geography = self.data[1].strip() self.targetGeoId = self.data[2].strip() self.targetGeoId2 = self.data[3].strip() self.popApr1 = self.data[4].strip() self.popJul1 = self.data[5].strip() self.changePop = self.data[6].strip() The problem is, I get an error saying:  ...
I am trying to do edge detection using matlab. I have posted code here. It does...
I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks! i = imread('C:\Users\Amanda\Desktop"); I = rgb2gray(1i); BW1 = edge(I,'prewitt'); BW2= edge(I,'sobel'); BW3= edge(I,'roberts'); subplot (2,2,1); imshow(I); title('original'); subplot(2,2,2); imshow(BW1); title('Prewitt'); subplot(2,2,3); imshow(BW2); title('Sobel'); subplot(2,2,4); imshow(BW3); title('Roberts');
Python Programming, Below included the Skeleton, input and output. Could you also include indents in the...
Python Programming, Below included the Skeleton, input and output. Could you also include indents in the solutions. In this programming laboratory you will create a Python program that evaluates the sum of the following mathematical series: Sum = x0 / 0! + x1 / 1! + x2 / 2! + x3 / 3! + … + xn / n!                  The variable x is a real (float) number and the variable n is an integer that can assume values greater than...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT