From: Eric S. Raymond Date: Mon, 27 Aug 2012 10:46:30 +0000 (-0400) Subject: Add UDP support and default to it. X-Git-Tag: 1.0~99 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a1cc3e9955213db84999ea0e0664619c8d6f8c9;p=irker.git Add UDP support and default to it. --- diff --git a/irker.py b/irker.py index 7986e19..376a956 100755 --- a/irker.py +++ b/irker.py @@ -159,17 +159,24 @@ class Irker: for session in self.sessions.values(): session.await() -class MyTCPHandler(SocketServer.StreamRequestHandler): +class IrkerTCPHandler(SocketServer.StreamRequestHandler): def handle(self): while True: irker.handle(self.rfile.readline().strip()) +class IrkerUDPHandler(SocketServer.BaseRequestHandler): + def handle(self): + data = self.request[0].strip() + #socket = self.request[1] + irker.handle(data) + if __name__ == '__main__': host = HOST port = PORT namesuffix = None debuglevel = 0 - (options, arguments) = getopt.getopt(sys.argv[1:], "d:p:n:") + tcp = False + (options, arguments) = getopt.getopt(sys.argv[1:], "d:p:n:t") for (opt, val) in options: if opt == '-d': debuglevel = int(val) @@ -177,8 +184,13 @@ if __name__ == '__main__': port = int(val) elif opt == '-n': namesuffix = val + elif opt == '-t': + tcp = True irker = Irker(debuglevel=debuglevel, namesuffix=namesuffix) - server = SocketServer.TCPServer((host, port), MyTCPHandler) + if tcp: + server = SocketServer.TCPServer((host, port), IrkerTCPHandler) + else: + server = SocketServer.UDPServer((host, port), IrkerUDPHandler) try: server.serve_forever() except KeyboardInterrupt: