See a lot, not very early not updated, is not support gevent
Finally, Sleekxmpp was chosen.
#!/usr/bin/env python# -*- coding: utf-8 -*-# https://github.com/fritzy/ sleekxmpp/tree/develop/examplesimport sysif "Threading" in sys.modules: print ("threading module loaded before patching!", "Xmppclient") del sys.modules["threading"]from Gevent import monkey; monkey.patch_all () from gevent.queue import queuefrom Sleekxmpp.util.misc_ops import setdefaultencoding; setdefaultencoding ("UTF8") import Sleekxmppimport loggingimport geventclass xmppclient (sleekxmpp. CLIENTXMPP): def __init__ (self, jid, password, address): super (xmppclient, self). __init__ (Jid, password) self.register_plugin ("xep_0030") # Service Discovery self.register_plugin ("xep_0004") # Data Forms self.register_plugin ("xep_0060") # PubSub self.register_plugin ("xep_0199") # XMPP Ping self.inbox = queue () self.address = address self.job_send = None # Add Event Trigger-start trigger self.add_event_ Handler ("Session_Start", self.session_start, threaded=true) # Add Event trigger-Receive message trigger &nbsP; self.add_event_handler ("message", self.message) if self.connect ( Address): self.process (Block=False) print "xmpp connected" self.init () else: print " Unable to connect. " def session_start (self, event): "" " Arguments: event -- an empty dictionary. the session_start& nbsp; event does not provide any additional data. "" " self.send_presence () self.get_roster () # self.send_message (mto=self.target_jid,# Mbody= "Ooxx",# mtype= "chat") &nbSp; def message (self, msg): print msg ["Type"], msg["Body"], msg["from"], msg["Lang"]# if msg["type"] in ("chat", "normal"):# msg.reply ("thanks for sending\n% (body) S" % msg). Send () def put_data (self, data): "" Send Message functions @param data: (target_jid, mtype, msg) "" " self.inbox.put (data) def send_data (self): while true: &nBsp; data = self.inbox.get () target_jid, mtype, msg = data self.send_message (Mto=target_jid, mbody=msg, mtype=mtype) def init ( Self): self.job_send = job_send = Gevent.spawn (Self.send_data) def _exit (Glet): job_send.unlink (_exit) Self.disconnect (Wait=false) job_send.link (_exit)  &Nbsp; if __name__ == "__main__": logging.basicconfig (level=logging. error, format= "% (levelname) -8s % (message) s") xmpp = xmppclient ("[email protected]", "123456", (" The-xmpp-server-ip ", 5222)) xmpp.put_data ((" [email protected] ", " chat ", "Ooxx") xmpp = xmppclient ("[email Protected] ", " 123456 ", (" The-xmpp-server-ip ", 5222)) xmpp.put_data ((" [ Email protected] ", " chat ", " Xxoo ")) gevent.wait ( )
Python Client for XMPP