import sys
import socket
-JTORXPORT = 8887
+JTORXPORT = 8888
if __name__ == "__main__":
serverPort = 10000
print 'Connected by JTorx at {}'.format(addr)
sender = None
seqnr = None
+ response = ''
while True:
data = conn.recv(1024)
if not data:
break
data = data.strip()
if data == 'Listen?':
- sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=1)
+ sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0)
response = ''
if data == 'SYN?':
seqnr = 100
+ print 'S: {}'.format(seqnr)
response = sender.sendInput('S', seqnr, seqnr)
- response = response[0]
if data == 'ACK?':
seqnr += 1
- response = sender.sendInput('S', seqnr, sender.lastSeqReceived + 1)
- response = response[0]
- print 'received: {}'.format(data)
-
+ print 'A: {}'.format(seqnr)
+ response = sender.sendInput('A', seqnr, sender.lastSeqReceived + 1)
+ if data == 'FINACK?':
+ seqnr += 1
+ print 'FA: {}'.format(seqnr)
+ response = sender.sendInput("FA", seqnr, sender.lastSeqReceived + 1)
+ if data == 'FIN?':
+ seqnr += 1
+ print 'F: {}'.format(seqnr)
+ response = sender.sendInput("F", seqnr, sender.lastSeqReceived + 1)
+ if data == 'RST?':
+ seqnr += 1
+ print 'RP: {}'.format(seqnr)
+ response = sender.sendInput("RP", seqnr, 0)
+ sender.sendReset()
+ if response:
+ if response == 'Timeout':
+ print 'data: {} - TIMEOUT!'.format(data)
+ conn.send('TIMEOUT!\n')
+ elif response[0] == 'A':
+ print 'data: {} - ACK!'.format(data)
+ conn.send('ACK!\n')
+ elif response[0] == 'R':
+ print 'data: {} - RST!'.format(data)
+ conn.send('RST!\n')
+ elif response[0] == 'SA':
+ print 'data: {} - SYNACK!'.format(data)
+ conn.send('SYNACK!\n')
+ else:
+ print 'data: {}'.format(data)
+
print 'closed'
conn.close()
exit()
- # isLocal is True if the interface is a local one
-
- # 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!'