Example #1
0
 def run(self):
    pinged = {}
    
    while 1:
       allclients = DB.get_all_connections()
       for c in allclients:
          #go through all connected clients and see if they need to be pinged for inactivity.
          if c['socket'] and c['last_action'] < (time.time() - 30):
             if pinged[c['name']]:
                #You've already pinged this client, check if it has ponged in time.
                if pinged[c['name']] < time.time() - 5:
                   #irresponsive client, drop it
                   plogger.info("Client %s (%s) didn't respond to ping, dropping it."\
                      % (c['name'], c['socket'].getaddress()[0]))
                   actions.drop_client_by_socket(c['socket'])
                   
             else:
                #Clients needs to be pinged: do it.
                pinged[c['name']] = time.time()
                plogger.info("Client %s (%s) inactive for over 30 s. Sending ping"\
                   % (c['name'], c['socket'].getaddress()[0]))
                actions.unicast(140, 'letsping', c['socket'])
             
          else:
             #This client has recent activity, don't ping.
             pinged[c['name']] = None
       time.sleep(1)
Example #2
0
    def run(self):
        pinged = {}

        while 1:
            allclients = DB.get_all_connections()
            for c in allclients:
                #go through all connected clients and see if they need to be pinged for inactivity.
                if c['socket'] and c['last_action'] < (time.time() - 30):
                    if pinged[c['name']]:
                        #You've already pinged this client, check if it has ponged in time.
                        if pinged[c['name']] < time.time() - 5:
                            #irresponsive client, drop it
                            plogger.info("Client %s (%s) didn't respond to ping, dropping it."\
                               % (c['name'], c['socket'].getaddress()[0]))
                            actions.drop_client_by_socket(c['socket'])

                    else:
                        #Clients needs to be pinged: do it.
                        pinged[c['name']] = time.time()
                        plogger.info("Client %s (%s) inactive for over 30 s. Sending ping"\
                           % (c['name'], c['socket'].getaddress()[0]))
                        actions.unicast(140, 'letsping', c['socket'])

                else:
                    #This client has recent activity, don't ping.
                    pinged[c['name']] = None
            time.sleep(1)
Example #3
0
 def run(self):
    while 1:
       #wait for the next message, 
       msg = self.client.receive()
       
       if len(msg) == 0:
          #for some reason, the connection was closed from the other end.
          #remove the client.
          logger.debug("empty message from %s. Assuming client dead." % self.client.getaddress()[0])
          actions.drop_client_by_socket(self.client)
          del(self.sock)
          return
       
       logger.debug("Recieved message from %s" % self.client.getaddress()[0])
       
       if msg:
          #unpack the received message and process it.
          decoded = Unpacker(msg).get()
          s = serveraction.ServerAction(decoded[1], decoded[2], self.client, '')
          s.start()