From 6e902ac79130df53312137e7dad6df6597d9e3d7 Mon Sep 17 00:00:00 2001 From: charlie Date: Sun, 20 Dec 2015 19:41:41 +0100 Subject: [PATCH] changes to gast adapter. --- a3/code/adapter/listener.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/a3/code/adapter/listener.py b/a3/code/adapter/listener.py index 1cb7981..f6a0905 100644 --- a/a3/code/adapter/listener.py +++ b/a3/code/adapter/listener.py @@ -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 -- 2.20.1