From 64cbeb6ce456b28c0ddba30727e7f54cdc93b29d Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 17 Dec 2020 11:13:35 +0100 Subject: [PATCH] renamed protocoll -> protocol --- .gitignore | 1 + net.py | 10 +++++----- protocoll.py => protocol.py | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) rename protocoll.py => protocol.py (92%) mode change 100644 => 100755 diff --git a/.gitignore b/.gitignore index c9b568f..ffffad6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc *.swp +pycrc diff --git a/net.py b/net.py index 9092936..61655fc 100755 --- a/net.py +++ b/net.py @@ -6,7 +6,7 @@ import logging import traceback from threading import Thread from time import sleep -from protocoll import * +from protocol import * logger = logging.getLogger(__name__) @@ -35,7 +35,7 @@ class NetServer(Thread): except: continue logger.debug("New Connection") - proto = Protocoll(NetWrapper(conn)) + proto = Protocol(NetWrapper(conn)) if self.handler_connect: self.handler_connect(proto) while True: @@ -85,7 +85,7 @@ class NetWrapper: def close(self): return self.sck.close() -class NetClient(Protocoll, Thread): +class NetClient(Protocol, Thread): def __init__(self, kTarget, handler=None): Thread.__init__(self) self.setDaemon(True) @@ -93,7 +93,7 @@ class NetClient(Protocoll, Thread): self.comm.connect(kTarget) self.comm.setblocking(0) self.comm.settimeout(0.01) - Protocoll.__init__(self, NetWrapper(self.comm)) + Protocol.__init__(self, NetWrapper(self.comm)) self.handler = handler self.bRun = False @@ -124,7 +124,7 @@ class NetClient(Protocoll, Thread): while True: i+=1 try: - return Protocoll.receive(self) + return Protocol.receive(self) except: if i > 300: raise diff --git a/protocoll.py b/protocol.py old mode 100644 new mode 100755 similarity index 92% rename from protocoll.py rename to protocol.py index 5beea6e..eb31a52 --- a/protocoll.py +++ b/protocol.py @@ -30,7 +30,7 @@ class PackageTooBigException(Exception): return "Package too long" -class Protocoll: +class Protocol: ENQ = 0x5 ACK = 0x6 DC1 = 0x11 @@ -146,3 +146,16 @@ class Protocoll: if addr_part == addr: msg+=msg_part return addr, msg + +if __name__ == "__main__": + import sys + if (len(sys.argv) > 2): + # sender + with open(sys.argv[1], "a+") as f: + p = Protocol(f) + p.write(int(sys.argv[2]), sys.argv[3]) + else: + # receiver + with open(sys.argv[1], "a+") as f: + p = Protocol(f) + print p.read() -- 2.39.5