Skip to content

Instantly share code, notes, and snippets.

@soulfly
Created January 29, 2016 11:23
Show Gist options
  • Save soulfly/d287aaef7f524e926b5c to your computer and use it in GitHub Desktop.
Save soulfly/d287aaef7f524e926b5c to your computer and use it in GitHub Desktop.
Python script to test duration time of XMPP login to QuickBlox Chat
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