-from sender import Sender\r
-import sys\r
-\r
-# before running this program, be sure to run the TCPServer\r
-# also make sure to run the below command to prevent the OS from canceling our connection\r
-# sudo iptables -A OUTPUT -p tcp --tcp-flags PSH PSH -j ACCEPT\r
-# sudo iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP\r
-\r
-# for running tests, you may need to store information on the received sequence number for the server\r
-# you can do that by defining new fields within the sender class/global variables to store such info\r
-\r
-# for non local communication, you can comment the raw sockets setting in sender.py (line 132)\r
-\r
-# run using sudo (!!!) from a command line terminal\r
-# and don't mind/ignore eclipse's red markings.\r
-\r
-if __name__ == "__main__":\r
- serverPort = 10000\r
- if len(sys.argv) > 1:\r
- serverPort = int(sys.argv[1])\r
- sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=1)\r
- # isLocal is True if the interface is a local one\r
- response = sender.sendInput("S", 100, 100) \r
-\r
- # triggers the response SA _ 101 if the server is listening on the specified port\r
- # if the server isn't listening, there are no responses\r
- print sender.lastAckReceived\r
- print sender.isTimeout\r
- \r
- # an example for the echo handling server\r
- if sender.isTimeout == False: # in case something was received\r
- sender.sendInput("A", 101, sender.lastSeqReceived + 1) # connection is established\r
- sender.sendInput("A", 101, sender.lastSeqReceived + 1, data = "C") # send some data\r
- sender.sendInput("A", 102, sender.lastSeqReceived + 1, data = "C") # send some data\r
- sender.sendInput("FA", 103, sender.lastSeqReceived + 1) # close connection (the echo also closes)\r
- sender.sendInput("RP", 104, 0) # reset connection\r
- \r
- sender.sendReset() # switch sender port\r
+#!/usr/bin/python
+from sender import Sender
+import sys
+
+if __name__ == "__main__":
+ serverPort = 10000
+ if len(sys.argv) > 1:
+ serverPort = int(sys.argv[1])
+ 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!'