如何使用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();
});
}
答案 0 :(得分:1)
cl.addListener('stanza', function(stanza) {
connection.write(stanza.children[1].children);
console.log(stanza.children[1].children);
});