node-xmpp C2SServer连接问题注册

我正在使用node-xmpp库与ubuntu上安装的ejabberd服务器进行通信。

我有以下脚本来注册和执行服务器中的操作..

var xmpp = require("node-xmpp"); var c2s = new xmpp.C2SServer({ port: 5223, domain: 'domain.com' }); c2s.on('connect', function(client) { console.log('connect ??? ++++++++'); c2s.on('register', function(opts, cb) { console.log('REGISTER') cb(true) }) client.on('authenticate', function(opts, cb) { console.log('AUTH' + opts.jid + ' -> ' +opts.password) cb(null) // cb(false) }) client.on('disconnect', function() { console.log('DISCONNECT') }) }); 

我能够在服务器中看到连接消息。 但是它没有调用注册事件。

不过,我有另一个在5222端口ejabberd实例工作正常从Audium XMPP客户端注册。

只需更改注册事件cb(true)cb(false) ..现在应该工作:)

如果您正在编写自己的服务器, xmpp.C2SServer是一个构build块。

如果要连接到现有的XMPP服务器,则需要使用:

 import xmpp from 'node-xmpp-client' const client = new xmpp.Client( ... ) 

然后按照XEP-0077在服务器上注册一个帐户。