eerste test
authormart <mart@lubbe.rs>
Wed, 11 Nov 2015 12:36:23 +0000 (13:36 +0100)
committermart <mart@lubbe.rs>
Wed, 11 Nov 2015 12:36:23 +0000 (13:36 +0100)
a2/code/client/testgeneration.py [new file with mode: 0755]

diff --git a/a2/code/client/testgeneration.py b/a2/code/client/testgeneration.py
new file mode 100755 (executable)
index 0000000..17e7c9e
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+from sender import Sender
+import sys
+
+def test(serverPort):
+    sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=1)
+    # isLocal is True if the interface is a local one
+    response = sender.sendInput("S", 100, 100) 
+
+    # triggers the response SA _ 101 if the server is listening on the specified port
+    # if the server isn't listening, there are no responses
+    print sender.lastAckReceived
+    print sender.isTimeout
+    
+    # an example for the echo handling server
+    if sender.isTimeout == False: # in case something was received
+        sender.sendInput("A", 101, sender.lastSeqReceived + 1) # connection is established
+        sender.sendInput("A", 101, sender.lastSeqReceived + 1, data = "Hello world!") # send some data
+        sender.sendInput("FA", 103, sender.lastSeqReceived + 1) # close connection (the echo also closes)
+        sender.sendInput("RP", 104, 0) # reset connection
+   
+    sender.sendReset() # switch sender port
+    print 'Succes!'
+
+
+if __name__ == "__main__":
+    serverPort = 10000
+    if len(sys.argv) > 1:
+        serverPort = int(sys.argv[1])
+    test(serverPort)