为什么FCM停止向我的XMPP客户端发送消息?

时间:2019-07-08 10:49:07

标签: firebase-cloud-messaging xmpp sleekxmpp

我使用sleekxmpp,我的xmpp客户端在10分钟内运行良好,但之后FCM停止向我发送消息 连接仍然打开,但是我的客户端没有收到来自FCM的更多消息

那么,为什么会发生这种情况?

我定期发送ping命令以保持连接状态 https://xmpp.org/extensions/xep-0199.html 而且我也尝试定期发送空白,但总是在FCM 10分钟后才不向我发送消息

send_queue = deque()
class Client_xmpp:      
    def __init__(self):
        self.SASL_DOMAIN = 'fcm.googleapis.com'
        self.FCM_ENDPOINT = 'fcm-xmpp.googleapis.com'
        self.PORT = 5235
        self.PROJECT_ID = "secret"
        self.API_KEY = "secret" 
        self.client = GCM(self.PROJECT_ID+'@'+self.SASL_DOMAIN, self.API_KEY)
        self.unacked_messages_quota = 100

def onAcknowledge(self,error, message_id, _from):
    some code ////////////////////////  



def onDisconnect(self,draining):
        print 'inside onDisconnect'     
        self.client.connect((self.FCM_ENDPOINT , self.PORT ), use_ssl=True)


def onMessage(self,msg):
    some code ///////////////////////////               



def start(self):
        self.client.register_plugin('xep_0199', {'keepalive': True, 'interval': 10, 'timeout': 30}) 
        self.client.add_event_handler(XMPPEvent.DISCONNECTED,self.onDisconnect)     
        self.client.add_event_handler(XMPPEvent.MESSAGE, self.onMessage, threaded=True)             
        auth = self.client.connect((self.FCM_ENDPOINT , self.PORT ), use_ssl=True)      
        if not auth:
          print 'Authentication failed!'
          sys.exit(1)       
        self.client.process(block=False)    
        while True:
            time.sleep(1)           
            self.flush_queued_messages()


def unique_id(self,msg_from):   
        return  str(datetime.utcnow())+msg_from

@property
def unacked_messages(self):
        return self.unacked_messages_quota

@unacked_messages.setter
def unacked_messages(self, value):
        self.unacked_messages_quota = value

def flush_queued_messages(self):                
        while len(send_queue) and self.unacked_messages > 0 :                   
            self.client.send_gcm(send_queue.popleft(),self.onAcknowledge)
            self.unacked_messages -= 1  

if __name__ == '__main__':      
        try:            
            client = Client_xmpp()
            client.start()  
        except Exception as e:          
            print "Unexpected error:", sys.exc_info()
            traceback.print_exc()

FCM在10分钟后停止向我发送消息,此后FCM与我的客户之间的唯一对话是ping定期

0 个答案:

没有答案