python-xmpp and looping through list of recipients to receive and IM message

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-05-12T02:45:07Z Indexed on 2010/05/12 2:54 UTC
Read the original article Hit count: 386

Filed under:
|
|

I can't figure out the problem and want some input as to whether my Python code is incorrect, or if this is an issue or design limitation of Python XMPP library. I'm new to Python by the way.

Here's snippets of code in question below. What I'd like to do is read in a text file of IM recipients, one recipient per line, in XMPP/Jabber ID format. This is read into a Python list variable.

I then instantiate an XMPP client session and loop through the list of recipients and send a message to each recipient. Then sleep some time and repeat test. This is for load testing the IM client of recipients as well as IM server. There is code to alternately handle case of taking only one recipient from command line input instead of from file.

What ends up happening is that Python does iterate/loop through the list but only last recipient in list receives message. Switch order of recipients to verify. Kind of looks like Python XMPP library is not sending it out right, or I'm missing a step with the library calls, because the debug print statements during runtime indicate the looping works correctly.


recipient = ""
delay = 60
useFile = False
recList = []
...
elif (sys.argv[i] == '-t'):
  recipient = sys.argv[i+1]
  useFile = False
elif (sys.argv[i] == '-tf'):
  fil = open(sys.argv[i+1], 'r')
  recList = fil.readlines()
  fil.close()
  useFile = True
...
# disable debug msgs
cnx = xmpp.Client(svr,debug=[])
cnx.connect(server=(svr,5223))
cnx.auth(user,pwd,'imbot')
cnx.sendInitPresence()

while (True):
  if useFile:
    for listUser in recList:
      cnx.send(xmpp.Message(listUser,msg+str(msgCounter)))
      print "sending to "+listUser+" msg = "+msg+str(msgCounter)
  else:
    cnx.send(xmpp.Message(recipient,msg+str(msgCounter)))
  msgCounter += 1
  time.sleep(delay)

© Stack Overflow or respective owner

Related posts about python

Related posts about xmpppy