In: Computer Science
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.
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....