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