Commit cda8e32f authored by wx002's avatar wx002

tested and worked w/ udpbox

parent 7add831c
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/csci363.iml" filepath="$PROJECT_DIR$/.idea/csci363.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -20,19 +20,6 @@ def get_decode_list(byteString):
return stringList
def get_line_index(stringList):
return stringList[0]
def verify_hash(stringList):
hash_str = stringList[1].encode()
recv_str = stringList[2]
if base64.b64decode(hash_str) == recv_str:
return True
else:
return False
def verify_packet_content(stringList):
'''
index 0: header index
......@@ -52,15 +39,19 @@ def verify_packet_content(stringList):
while True:
data, addr = sock.recvfrom(1048)
currentHash = None
print("recv data: {}".format(data))
#print("recv data: {}".format(data))
while data != b'####' and data != b'END':
lineStr += data.decode('utf-8')
try:
lineStr += data.decode('utf-8')
except Exception:
# bad packet ask for resend
sock.sendto(b'NAK', addr)
# print(get_decode_list(lineStr))
data, addr = sock.recvfrom(1048)
if data == b'####':
packetList = get_decode_list(lineStr)
print(packetList)
#print(packetList)
# check header
if currentHash != packetList[0]:
print('got new packet')
......@@ -74,7 +65,7 @@ while True:
else: # duplicated packet, resend ack
sock.sendto(b'ACK', addr)
print(fileList)
# print(fileList)
lineStr = ''
# data = ''
#print(fileList)
......@@ -85,6 +76,7 @@ while True:
print("got all contents!")
sock.close()
# make file
file = open('recv.txt', 'w+')
file = open('recvData/recv.txt', 'w+')
file.writelines(fileList)
exit(1)
file.close()
exit(0)
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -45,6 +45,8 @@ def rdt_sendFile(network, dest, filename, size=65536):
print(data)
if data == b'ACK':
ack = True
if data == b'NAK':
send_line(network, dest, hashed_line, size)
except socket.timeout:
print('timeout! resend line')
send_line(network, dest, hashed_line, size)
......@@ -53,7 +55,7 @@ def rdt_sendFile(network, dest, filename, size=65536):
if __name__ == '__main__':
ip = '127.0.0.1'
port = 8888
port = 8880
dest = (ip, port)
timeOut = 1
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment