コード例 #1
0
ファイル: test_server.py プロジェクト: yishaibeeri/greendns
def udp_server_process():
    s1 = socketserver.UDPServer(("127.0.0.1", random.randint(20000, 30000)),
                                UdpEcho1Handler)
    server_addr1 = s1.server_address
    p1 = Process(target=s1.serve_forever)
    p1.start()
    s2 = socketserver.UDPServer((myip, random.randint(20000, 30000)),
                                UdpEcho2Handler)
    server_addr2 = s2.server_address
    p2 = Process(target=s2.serve_forever)
    p2.start()
    yield (server_addr1, server_addr2)
    p1.terminate()
    p2.terminate()
コード例 #2
0
 def run_logstash(self):
     """
     Runs a socketserver instance emulating Logstash
     """
     self.logstash = socketserver.UDPServer(('0.0.0.0', 0), LogstashHandler)
     threading.Thread(target=self.logstash.serve_forever).start()
     return self.logstash
コード例 #3
0
ファイル: test_ioloop.py プロジェクト: yishaibeeri/greendns
def udp_server_process():
    s = socketserver.UDPServer(("127.0.0.1", random.randint(20000, 30000)),
                               UdpEchoHandler)
    p = Process(target=s.serve_forever)
    p.start()
    yield s.server_address
    p.terminate()
コード例 #4
0
 def start(cls, callback, host, port=514, poll_interval=0.5, **kwargs):
     cls.kwargs = kwargs
     cls.callback = callback
     # TODO Test exception propagation to the main thread (due to a bad host?), may need handling
     try:
         server = socketserver.UDPServer((host, port), cls)
         server.serve_forever(poll_interval=poll_interval)
     except (IOError, SystemExit):
         raise
     except KeyboardInterrupt:
         logger.info("Crtl+C Pressed. Shutting down.")
コード例 #5
0
ファイル: syslog.py プロジェクト: theopolis/theopolis_plugins
def runSyslogServer(host, port, logfile):
    """Run a dummy syslog server.

    :param host: IP address to listen
    :param port: Port to listen
    :param logfile: File handle used to write incoming logs
    """
    logfilehandle = open(logfile, "w+")
    handler = SyslogUDPHandler
    handler.outputHandle = logfilehandle
    syslogd = socketserver.UDPServer((host, port), handler)

    def serve():
        syslogd.serve_forever()

    thread = threading.Thread(target=serve)
    thread.start()
    return syslogd