gpt4 book ai didi

node.js - 如何从 ejabberd 客户端接收消息到 node-xmpp

转载 作者:搜寻专家 更新时间:2023-11-01 00:03:24 25 4
gpt4 key购买 nike

如何使用node-xmpp接收来自客户端的消息...?

我已经知道怎么发消息了

这里是如何发送消息的示例代码...

var net = require("net");
var xmpp = require('node-xmpp');

var server = net.createServer(
function(socket) {

socket.setEncoding("utf8");
socket.on('data',function(data) {
chat(data,socket);
});
}
);
server.listen(3000);

var chat = function(data,socket) {
var cl = new xmpp.Client({ jid: 'admin@mine',password: '12345' });

cl.on('online',
function() {
cl.send(new xmpp.Element('message',
{ to: 'test@mine',
type: 'chat'}).
c('body').
t(data));


// nodejs has nothing left to do and will exit
cl.end();
});
}

最佳答案

cl.addListener('stanza', function(stanza) {
connection.write(stanza.children[1].children);
console.log(stanza.children[1].children);
});

关于node.js - 如何从 ejabberd 客户端接收消息到 node-xmpp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com