title: NodeJS xmpp server
body: <p>I make the first steps in the node js and xmpp</p>
  
  <p>I need to run at xmpp server on node js for messaging</p>
  
  <p>Here's the process:
  I use node-xmpp server <a href="https://github.com/astro/node-xmpp">https://github.com/astro/node-xmpp</a>
  run the example of a server (/examples/c2s.js)
  join to server with two clients (clients tested on other servers jabber - it works and the messages are sending through)</p>
  
  <p>Clients have authorization on my server.
  But when I send a message from one client to another, the message comes to the server (I see it in the logs)
  and that was the message does not come to recipient</p>
  
  <p>I don `t know where to look for the problem
  server configuration ? routing ? messaging may be necessary to add yourself ?</p>
  
  <p>help me plz</p>
  
  <p>my server code (by examples)</p>
  
  <pre><code>var xmpp = require('../lib/node-xmpp');
  
  var c2s = new xmpp.C2SServer({
      port: 5222,
      domain: 'localhost'
  
  });
  
  // On Connect event. When a client connects.
  c2s.on("connect", function(client) {
      c2s.on("register", function(opts, cb) {
          console.log("REGISTER");
      cb(true);
      });
  
      client.on("authenticate", function(opts, cb) {
          console.log("AUTH" + opts.jid + " -&gt; " +opts.password); 
      cb(null); 
      });
  
      client.on("online", function() {
          console.log("ONLINE");
          client.send(new xmpp.Message({ type: 'chat' }).c('body').t("Hello there, little client."));
      });
  
      client.on("stanza", function(stanza) {
          console.log("STANZA" + stanza);
  
      });
  
      client.on("disconnect", function(client) {
          console.log("DISCONNECT");
      });
  
  });
  </code></pre>
  
  <p>I run a server and connect to it by this code</p>
  
  <pre><code>var xmpp = require('../lib/node-xmpp');
  var argv = process.argv;
  
  if (argv.length &lt; 6) {
      console.error('Usage: node send_message.js &lt;my-jid&gt; &lt;my-password&gt; &lt;my-text&gt; &lt;jid1&gt; [jid2] ... [jidN]');
      process.exit(1);
  }
  
  var cl = new xmpp.Client({ jid: argv[2], password: argv[3] });
  
  cl.addListener('online',
     function() {argv.slice(5).forEach(
         function(to) {cl.send(new xmpp.Element('message', { to: to,type: 'chat'}).c('body').t(argv[4]));
         });
  
         // nodejs has nothing left to do and will exit
         // cl.end();
     });
  
  cl.addListener('stanza',
      function(stanza) {
          if (stanza.is('message') &amp;&amp;
              // Important: never reply to errors!
              stanza.attrs.type !== 'error') {
              console.log("New message");
              // Swap addresses...
              stanza.attrs.to = stanza.attrs.from;
              delete stanza.attrs.from;
              // and send back.
              cl.send(stanza);
          }
      });
  
  cl.addListener('error',
      function(e) {
         console.error(e);
         process.exit(1);
     });
  </code></pre>