title: Integrate cross-domain-socket.io using sails.io library to client
body: <p>I have written a chat application based on sails.js on my server so basiclly all the code in the client side was running on the localhost.</p>
  
  <p>the chat is working like a dream but now i want to move all the client side to my cordova application.</p>
  
  <p>this is my server side code(socket.js)</p>
  
  <pre><code>onConnect: function(session, socket) {
  
      // By default, do nothing.
      console.log('hello');
      socket.emit('news', "Welcome to the chat");
  
      socket.on('send message', function(data){
          console.log(data);
          socket.broadcast.emit('new', data);
          sails.sockets.emit(sails.sockets.id(socket),'new', data);
      });
  },
  </code></pre>
  
  <p>this is my client side(server localhost) chat file:</p>
  
  <pre><code>$('#form1').submit(function(e){
      e.preventDefault();
      io.socket.emit('send message', $('#userText').val());
      $('#userText').val('');
  });
  
  io.socket.on('news', function (msg) {
      console.log(msg);
      $('#content').append(msg + '&lt;br /&gt;');
  });
  
  io.socket.on('new', function(data){
      console.log(data);
      $('#content').append(data + '&lt;br /&gt;');
  });
  </code></pre>
  
  <p>and this is client side(server localhost) that request the userCategories API:</p>
  
  <pre><code>io.socket.get('http://178.62.83.248:1337/userCategories', function (resData)    {
     console.log(resData); // =&gt; {id:9, name: 'Timmy Mendez'}
  });
  
  io.socket.on('usercategories', function(message){
      console.log(message);
  });
  </code></pre>
  
  <p>now here is what i tried on my cordova client(index.js):</p>
  
  <pre><code>&lt;script src="lib/sails.io.js/sails.io.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      io.sails.url = 'http://178.62.83.248:1337';
      io.socket.get('http://178.62.83.248:1337/userCategories', function (resData) {
        console.log(resData); // =&gt; {id:9, name: 'Timmy Mendez'}
      });
  
      io.socket.on('usercategories', function(message){
          console.log(message);
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>this code acts in a very weird way.when the application starts, it tries to connect to: <a href="http://178.62.83.248:1337/__getcookie" rel="nofollow">http://178.62.83.248:1337/__getcookie</a>
  and then it fails? and returns me this message in the console:</p>
  
  <pre><code>        Socket is trying to reconnect to Sails...
   _-|&gt;_-  (attempt #1)
  
          Socket is trying to reconnect to Sails...
   _-|&gt;_-  (attempt #2)
  </code></pre>
  
  <p>attempt 43, 44, etc...</p>
  
  <p>so I hope someone can explain me what is this mean and how can I fix this.</p>