无法解码Node.js应用程序中ejabberd服务器的响应

时间:2015-08-08 13:21:18

标签: node.js ejabberd

我是node.js的全新手。我需要您的帮助以下代码。我试过执行它但我无法解码来自服务器的响应。感谢您的时间和努力。

var express = require('express');

var xmlrpc = require('xmlrpc');

// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');

// create a new express server
var app = express();

// serve the files out of ./public as our main files
app.use(express.static(__dirname + '/public'));


// Creates an XML-RPC server to listen to XML-RPC method calls
var server = xmlrpc.createServer({ host: 'localhost', port: 9090 });
// Handle methods not found
server.on('NotFound', function(method, params) {
  console.log('Method ' + method + ' does not exist');
});
// Handle method calls by listening for events with the method call name
server.on('anAction', function (err, params, callback) {
  console.log('Method call params for \'anAction\': ' + params);

  // ...perform an action...

  // Send a method response with a value
  callback(null, 'aResult');
});
console.log('XML-RPC server listening on port 9091');



// Waits briefly to give the XML-RPC server time to start up and start
// listening

var receiveraray;
setTimeout(function () {
  // Creates an XML-RPC client. Passes the host information on where to
  // make the XML-RPC calls.

  var client = xmlrpc.createClient({ host: 'host', port: 4560,  path: '/home/ec2-user/ejabberd-15.07/bin'});

  // Sends a method call to the XML-RPC server{call, user_resources, 

  client.methodCall('registered_users', [ {host: "host"} ], function (error, value) {
  //client.methodCall('ejabberdctl status', function (error, value) {
    // Results of the method response

    receiveraray = value;
    console.log('Method response for \'anAction\': ' + receiveraray);
    console.log('Method response for \'anAction\': ' + error);
  });

}, 1000);

我从ejabberd服务器的响应中获取此输出;

'anAction'的方法响应:[object Object] 'anAction'的方法响应:null

1 个答案:

答案 0 :(得分:0)

您访问ejabberd XMLRPC侦听器的参数似乎不正确:

var client = xmlrpc.createClient({ host: 'host', port: 4560,  path: '/home/ec2-user/ejabberd-15.07/bin'});

您指的是host,我猜您的意思是localhost。 这条路似乎完全破碎了。您正在尝试访问目录。通常,您可能希望路径为“/”,因为您要访问http://localhost:4560/以传递XMLRPC请求(取决于您的实际ejabberd配置)。