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

时间:2011-08-11 08:27:21

标签: node.js ejabberd node-xmpp

如何使用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();
               });
}

1 个答案:

答案 0 :(得分:1)

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