XMPPPY 无法连接到服务器

XMPPPY unable to connect to the server

我正在使用 xmpppy python 库与 XMPP 服务器 (ejabberd2) 连接,但无法连接,实际上不清楚如何连接、验证和向服务器发送消息。

请帮我让它工作

如果可能,请提供一些使用 XMPPPY 的代码片段。

我在朋友的帮助下找到了解决方案

它需要更改 XMPP ejabberd 服务器配置。 将行 {hosts, ["localhost"]} 更改为 {hosts, ["localhost", "server-domain", "server-ip-address"]} 在 ejabberd.cfg 文件中。

重启服务器,在新hosts下用服务器域名或服务器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"))