title: 'send' on 'WebSocket': already in CONNECTING state error
body: <p>I am using node.js &amp; sockets.io on a mac (whilst testing). The app is being tested as a web app and also as a phonegap compiled app on IOS. The error above appeared on the web app when the PC had gone to sleep overnight and I resumed the PC. </p>
  
  <p>On the web client I am using:</p>
  
  <pre><code>OnAppStarted{
  connectSocket();
  }
  
  function connectSocket(){
  socket = io.connect('http://XXX.XXX.XXX.XXX:8124', {
      'reconnect': true,
      'reconnection delay': 500,
      'max reconnection attempts': 50
  });
  
  //socket = io.connect('http://81.133.36.139:8124');
  socket.on('disconnect', function () { 
  //app.jGrowl('disconnected ');
  app.setProperty('labelTopText','fontColor','red');
  });   
  
  socket.socket.on('connect', function () { 
  app.jGrowl('sockets connected');
  var d = new Date();
  connectedTime = JSON.stringify(d);
  socket.emit('subscribe', {schoolNewsUpdated:'schoolNewsUpdated',schoolNewsClientUpdateTime : schoolNewsClientUpdateTime});
  app.setProperty('labelTopText','fontColor','white');
  });
  socket.on('disconnect', function () { 
  app.setProperty('labelTopText','fontColor','red');
  });   
  
  socket.on('update', function(data) {
  //app.jGrowl('on update ');
  var d = new Date();
  schoolNewsClientUpdateTime = d;
  if(data["schoolNewsUpdated"] === 'schoolNewsUpdated'){// &amp;&amp; schoolNewsLastUpdateTime &gt; data["schoolUpdatedTime"]  ){
  updatedNewsDocs = 'Y';
  handler_image_onClick();
  }
  });
  
  }
  }
  </code></pre>
  
  <p>I have the following events for when the app goes into the background.</p>
  
  <pre><code>function handler_application_onMobileResume(){
  socket.socket.reconnect();
  }
  
  
  function handler_application_onMobilePause(){
  socket.socket.disconnect(); 
  } 
  
  function handler_application_onMobileResume(){
  socket.socket.reconnect();
  }
  
  
  function handler_application_onMobilePause(){
  socket.socket.disconnect(); 
  }
  </code></pre>
  
  <p>Server Side:</p>
  
  <pre><code>// live version
  var io = require('socket.io').listen(8124);
  var roomID;
  var schoolNewsServerUpdateTime = '2014-01-10T22:52:50.904Z';
  var schoolRequestedTime;
  var schoolNewsClientUpdateTime;
  
  
  io.sockets.on('connection', function (socket) {
  socket.on('subscribe', function (data) {
  roomID = data["schoolNewsUpdated"];
  schoolNewsClientUpdateTime = JSON.stringify(data["schoolNewsClientUpdateTime"]);
  socket.join(roomID);
  console.log('joined room ' + roomID +' client update ' + schoolNewsClientUpdateTime + ' server update ' + schoolNewsServerUpdateTime);
  if(schoolNewsClientUpdateTime &lt; schoolNewsServerUpdateTime){
      console.log(' we should send an update to this client');
      socket.emit('update', {schoolNewsUpdated : 'schoolNewsUpdated'});
  }
  else
  {
  console.log(' no update as there is as he already has the latest')
  }
  });
  
  socket.on('unsubscribe', function (data) {
  
  roomID = data["schoolNewsUpdated"];
  socket.leave(roomID);
  console.log('left room ' + roomID);
  
  });
  
  socket.on('itemUpdated', function (data) {
  var createdFor = data.createdFor;
  var updatedChatID = data.updatedChatID;
  var d = new Date();
  schoolNewsServerUpdateTime = JSON.stringify(d);
  console.log('sending '+ updatedChatID +' to everyone in room '+ createdFor + ' created at ' + schoolNewsServerUpdateTime);
  socket.broadcast.to(createdFor).emit('update', {schoolNewsUpdated : updatedChatID});
  
  });
  });
  </code></pre>
  
  <p>So what happens is on my main 'Editor' app whenever I update a record this triggers the socket.io and sends a message to all clients in the same room. The clients then refresh the data and re-populate the controls.</p>
  
  <p>Any ideas what I need to do to stop the error appearing ?</p>
  
  <p>MrWarby</p>