Created
January 29, 2016 11:23
-
-
Save soulfly/d287aaef7f524e926b5c to your computer and use it in GitHub Desktop.
Python script to test duration time of XMPP login to QuickBlox Chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
from sleekxmpp import ClientXMPP | |
class EchoBot(ClientXMPP): | |
def __init__(self, jid, password): | |
ClientXMPP.__init__(self, jid, password) | |
self.add_event_handler("session_start", self.session_start) | |
self.add_event_handler("message", self.message) | |
def session_start(self, event): | |
self.send_presence() | |
self.end = time.time() | |
logging.log(logging.DEBUG, "LOGIN DONE, duration: " + str(self.end - self.start) + " seconds") | |
self.disconnect(wait=True) | |
def message(self, msg): | |
print(msg) | |
if __name__ == '__main__': | |
# Ideally use optparse or argparse to get JID, | |
# password, and log level. | |
logging.basicConfig(level=logging.DEBUG, | |
format='%(levelname)-8s %(asctime)s.%(msecs)03d: %(message)s', datefmt='%I:%M:%S') | |
JID = '[email protected]' | |
PASSWORD = 'igorquickblox711' | |
xmpp = EchoBot(JID, PASSWORD) | |
logging.log(logging.DEBUG, "START") | |
xmpp.start = time.time() | |
if xmpp.connect(): | |
xmpp.process(block=True) | |
else: | |
print('Unable to connect') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment