From: charlie Date: Sun, 20 Dec 2015 18:41:41 +0000 (+0100) Subject: changes to gast adapter. X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6e902ac79130df53312137e7dad6df6597d9e3d7;p=tt2015.git changes to gast adapter. --- 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