开发者

how to receive message from ejabberd client to node-xmpp

how to use node-xmpp to receive message from client...?

i already known how to sent message

here the sample code how to send message...

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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜