changes to gast adapter.
authorcharlie <somemail@something.com>
Sun, 20 Dec 2015 18:41:41 +0000 (19:41 +0100)
committercharlie <somemail@something.com>
Sun, 20 Dec 2015 18:41:41 +0000 (19:41 +0100)
a3/code/adapter/listener.py

index 1cb7981..f6a0905 100644 (file)
@@ -15,7 +15,7 @@ if __name__ == "__main__":
     print 'Listening on port {} for Gast'.format(GASTPORT)
     conn, addr = s.accept()
     print 'Connected by Gast at {}'.format(addr)
-    sender = None
+    sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0)
     seqnr = None
     response = ''
     data = ''
@@ -30,6 +30,41 @@ if __name__ == "__main__":
         
         data = conn.recv(int(data))
         print "INPUT: "+data
+       
+        if data == 'SYN':
+            seqnr = 100
+            print 'S: {}'.format(seqnr)
+            response = sender.sendInput('S', seqnr, seqnr)
+        elif data == 'ACK':
+            seqnr += 1
+            print 'A: {}'.format(seqnr)
+            response = sender.sendInput('A', seqnr, sender.lastSeqReceived + 1)
+        elif data == 'RST':
+            seqnr += 1
+            print 'RP: {}'.format(seqnr)
+            response = sender.sendInput("RP", seqnr, 0)
+            sender.sendReset()
+        elif data == 'FIN':
+            seqnr += 1
+            print 'F: {}'.format(seqnr)
+            response = sender.sendInput("FA", seqnr, sender.lastSeqReceived + 1)
+        else:
+            print 'INVALID INPUT!'
+            break
+
+        if response == 'Timeout':
+            data = 'TO'
+        elif response[0] == 'A':
+            data = 'ACK'
+        elif response[0] == 'R':
+            data = 'RST'
+        elif response[0] == 'SA':
+            data = 'SYN-ACK'
+        else:
+            data = 'ERR'
+        
+        print 'RESPONSE: '+data
+        conn.send('{} {}'.format(len(data), data));        
         
         data = ''
         continue