Pyxmpp: quick tutorial for creating a muc client?

I am trying to write a quick load-test script for our ejabberd cluster that just enters the chat room, sends some random messages, and then exits.

We tried to run this particular test with tsung, but according to the authors, the muc function was not included in this release.

pyxmpp seems to have this functionality, but darn, if I can figure out how to make it work. Here, I hope someone quickly explains how to build a client and join / send to muc.

Thanks!

+6
python xmpp ejabberd multiuserchat
source share
1 answer

Hey, I stumbled upon your question several times, trying to do the same. Here is my answer:

Using http://pyxmpp.jajcus.net/svn/pyxmpp/trunk/examples/echobot.py as a quick start, all you have to do is import the muc-stuff

from pyxmpp.jabber.muc import MucRoomState, MucRoomManager 

And once your client is connected, you can connect to your room:

 def session_started(self): """Handle session started event. May be overriden in derived classes. This one requests the user roster and sends the initial presence.""" print u'SESSION STARTED' self.request_roster() p=Presence() self.stream.send(p) print u'ConnectToParty' self.connectToMUC() def connectToMUC(self): self.roomManager = MucRoomManager(self.stream); self.roomHandler = MucRoomHandler() self.roomState = self.roomManager.join( room=JID(' room@conference.server.domain '), nick='PartyBot', handler=self.roomHandler, history_maxchars=0, password = None) self.roomManager.set_handlers() 

To send a message, all you have to do is call self.roomState.send_message ("Sending this message")

Make material, inherit from MucRoomHandler and respond to events. Note the "set_handlers ()" on the roomManager, although this is important, otherwise callbacks will not be called.

+6
source share

All Articles