コード例 #1
0
 def getService(self):
     f = SIPServer()
     f.factory = self
     return internet.UDPServer(self.port, f, interface=self.listen_addr)
コード例 #2
0
 def onStop(ignored):
     t = internet.UDPServer(num, p)
     t.startService()
     return t.stopService()
コード例 #3
0
            self.callback(ip)

class DetectorService(internet.TimerService):
    """Detect clients not sending heartbeats for too long"""

    def __init__(self):
        internet.TimerService.__init__(self, CHECK_PERIOD, self.detect)
        self.beats = {}

    def update(self, ip):
        self.beats[ip] = time.time()

    def detect(self):
        """Log a list of clients with heartbeat older than CHECK_TIMEOUT"""
        limit = time.time() - CHECK_TIMEOUT
        silent = [ip for (ip, ipTime) in self.beats.items() if ipTime < limit]
        log.msg('Silent clients: %s' % silent)

application = service.Application('Heartbeat')
# define and link the silent clients' detector service
detectorSvc = DetectorService()
detectorSvc.setServiceParent(application)
# create an instance of the Receiver protocol, and give it the callback
receiver = Receiver()
receiver.callback = detectorSvc.update
# define and link the UDP server service, passing the receiver in
udpServer = internet.UDPServer(UDP_PORT, receiver)
udpServer.setServiceParent(application)
# each service is started automatically by Twisted at launch time
log.msg('Asynchronous heartbeat server listening on port %d\n'
    'press Ctrl-C to stop\n' % UDP_PORT)
コード例 #4
0
ファイル: sip.py プロジェクト: tdr130/opencanary
 def getService(self):
     f = SIPServer()
     f.factory = self
     return internet.UDPServer(self.port, f)
コード例 #5
0
 def startService(self):
     udpservice = internet.UDPServer(self.port, self.protocol, interface="0.0.0.0")
     udpservice.startService()
     log.msg("Nameserver listening on port %d" % self.port)
     self.services.append(udpservice)
     self.drop_privileges()