ソースを参照

i swear it worked once

tarfeef101 6 年 前
コミット
44977097cc
6 ファイル変更20 行追加17 行削除
  1. BIN
      a2/__pycache__/packet.cpython-35.pyc
  2. 2 0
      a2/cleanup.sh
  3. 0 0
      a2/nEmulator-linux386
  4. 0 0
      a2/packet.py
  5. 5 5
      a2/receiver.py
  6. 13 12
      a2/sender.py

BIN
a2/__pycache__/packet.cpython-35.pyc


+ 2 - 0
a2/cleanup.sh

@@ -0,0 +1,2 @@
+#!/bin/bash
+rm ack.log arrival.log segnum.log output.txt

+ 0 - 0
a2/nEmulator-linux386


+ 0 - 0
a2/packet.py


+ 5 - 5
a2/receiver.py

@@ -1,10 +1,10 @@
-from . import packet
+from packet import packet
 import socket, sys
 
 # save values needed to talk to host emulator
 haddr = sys.argv[1] # network host address
-dport = sys.argv[2] # dest port on host
-rport = sys.argv[3] # recv port for this app
+dport = int(sys.argv[2]) # dest port on host
+rport = int(sys.argv[3]) # recv port for this app
 received = sys.argv[4] # filename to be used to record recvd data
 
 # try opening the file
@@ -36,7 +36,7 @@ while(True):
         packet = packet.parse_udp_data(pack)
         
     snum = packet.seq_num
-    arrlog.write(str(snum))
+    arrlog.write(str(snum) + "\n")
     
     if (snum == expected): # got the next packet
         if (packet.type == 2): # EOT packet
@@ -52,7 +52,7 @@ while(True):
             msgfile.write(packet.data)
             
     elif (confirmed): # got wrong packet, send confirmation only of last good packet
-        sock.sendto(packet.create_acl(confirmed).get_udp_data(), (haddr, dport))
+        sock.sendto(packet.create_ack(confirmed).get_udp_data(), (haddr, dport))
         
 
 arrlog.close()

+ 13 - 12
a2/sender.py

@@ -1,10 +1,10 @@
-from . import packet
+from packet import packet
 import socket, sys, os, threading
 
 # save values needed to talk to host emulator
 haddr = sys.argv[1] # network host address
-dport = sys.argv[2] # dest port on host
-rport = sys.argv[3] # recv port for this app
+dport = int(sys.argv[2]) # dest port on host
+rport = int(sys.argv[3]) # recv port for this app
 msg = sys.argv[4] # filename to be sent
 
 # logfiles (segnums and acks, respectively)
@@ -53,26 +53,27 @@ sock.bind(('localhost', rport))
 # start receiver thread
 # receiver function
 def receiver():
-    print("YAY!\n")
-    
+    #global confirmed   
+ 
     while(True):
         # get a packet, turn into packet type
         pack, addr = sock.recvfrom(pack_size)
-        packet = packet.parse_udp_data(pack)
+        newpacket = packet.parse_udp_data(pack)
         
         lock.acquire()
         # what type is this?
-        if (packet.type == 2): # EOT
-            acklog.write(str(packet.seq_num))
+        if (newpacket.type == 2): # EOT
+            acklog.write(str(newpacket.seq_num + "\n"))
             lock.release()
             return
-        elif (packet.type == 1): # data
+        elif (newpacket.type == 1): # data
             lock.release()
             sys.stderr.write("Got data from receiver. Exiting")
             raise SystemExit
         else: # ACK packet
-            acklog.write(str(packet.seq_num))
-            if (packet.seq_num > confirmed): # new ACK
+            acklog.write(str(newpacket.seq_num) + "\n")
+            print("snum: ", newpacket.seq_num, "confirmed: ", confirmed)
+            if (newpacket.seq_num > confirmed): # new ACK
                 confirmed = seq_num + 1
                 waking = True
                 cv.notify_all()
@@ -90,7 +91,7 @@ while (confirmed < total_packets):
     # while we have room for packets in the window, send some
     while(snum < confirmed + winsize and snum < total_packets):
         sock.sendto(packets[snum].get_udp_data(), (haddr, dport))
-        seglog.write(str(snum))
+        seglog.write(str(snum) + "\n")
         snum += 1
         
     # use cv to sleep for 0.2s, or if woken up