我正在使用 xmpppy python 库与 XMPP 服务器(ejabberd2)连接,但无法连接,实际上并不清楚如何连接、验证和向服务器发送消息。
请帮我让它工作
如果可能,请提供一些使用 XMPPPY 的代码片段。
我在朋友的帮助下找到了解决方案
它需要更改 XMPP ejabberd 服务器配置。在 ejabberd.cfg 文件中用{hosts, ["localhost", "server-domain", "server-ip-address"]}更改行{hosts, ["localhost"]} 。
重新启动服务器并在具有服务器域或服务器 ip 的新主机下创建另一个用户。
代码片段:
import xmpp
ipaddress='<server-ip>'
user='<new-user>' #without @<server-ip>
passwd='<password>'
c = xmpp.Client(ipaddress)
c.connect((ipaddress,5222), secure=0)
c.auth(user,passwd,sasl=1)
c.sendInitPresence()
c.isConnected()
c.send(xmpp.protocol.Message('<jid of receiver user with @<domain> >',"hello world"))