title: Getting socket.io working with phone gap
body: <p>I have come across many posts on here and various other sites about how to get socket.io working in an android phonegap app, unfortunately I still seem to be having problems. If you've had any experience of getting this kind of thing set up, any pointers you could give would be greatly appreciated, having now spent several days tearing my hair out :P</p>
  
  <p>So to get started I have a very simple socket.io server setup and running on my local machine:</p>
  
  <pre><code>var server = require('http').createServer();
  var io = require('socket.io')(server);
  
  io.sockets.on('connection', function (socket) {
      console.log('socket connected');
  
      socket.on('disconnect', function () {
          console.log('socket disconnected');
      });
  
      socket.emit('text', 'wow. such event. very real time.');
  });
  
  server.listen(3000);
  </code></pre>
  
  <p>which I got from one of the tutorials that I found, and it seems to work ok.</p>
  
  <p>Now in my phonegap app all the code I have is as follows:</p>
  
  <pre><code>var app = angular.module("MyApp", [
      "MyCtrl"
  ]);
  
  app.controller("AppCtrl", ["$scope", function ($scope) {
      console.log("About to attempt a connection (" + socket + ")!");
      var socket = io("10.0.5.159:3000");
      socket.on("connect", function(data) {
          console.log("Connected: " + data);
      });
      socket.on("error", function(err) {
          console.log("Error: " + err);
      });
  }]);
  </code></pre>
  
  <p>Just a basic angular.js app with a single controller that attempts to connect to the server (the ip address provided is the correct one on my local network). My log gets hit so I know this code is executed, but I never get a connect event or an error event, and no errors come up in the console, it just seems to fail silently. I also get no connection event on the server.</p>
  
  <p>As per another stackoverflow post I have ensured that my config.xml contains the appropriate</p>
  
  <pre><code>&lt;access origin="10.0.5.159*" /&gt;
  </code></pre>
  
  <p>entry. But I still seem to be getting nowhere with it. The same line of code</p>
  
  <pre><code>var socket = io("10.0.5.159:3000");
  </code></pre>
  
  <p>when executed in a safari browser window works exactly as expected and my server logs a connection event, so I'm confident that the server and the connect code are valid.</p>
  
  <p>Any ideas what I might be doing wrong?</p>