2011-08-11 120 views
3

如何使用node-xmpp從客戶端接收消息...?如何從ejabberd客戶端接收消息到節點-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: '[email protected]',password: '12345' }); 

     cl.on('online', 
       function() { 
          cl.send(new xmpp.Element('message', 
                { to: '[email protected]', 
                 type: 'chat'}). 
            c('body'). 
            t(data)); 


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

回答

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