title: How to disconnect and reconnect socket.io from client?
body: <p>I have log messages that are being emitted from server to client and that are coming consistently from server and logging to client, Now I have additional functionality to stop and play logs to give some controls to user, So I am thinking on stop to disconnect <code>socket.io</code> connection and on play start <code>socket.io</code> connection again, First i am trying with stop to disconnect connection but i could not emit message to server ,any idea what is wrong with below code or any better solution to achieve these task ?
  main.html</p>
  
  <pre><code>&lt;button type="button" class="btn btn-success" ng-click="stopLogs()"&gt;stop&lt;/button&gt;
  </code></pre>
  
  <p>ctrl.js</p>
  
  <pre><code>$scope.stopLogs = function(){
          socket.emit('end');
      }
  </code></pre>
  
  <p>angularSOcketFactory.js</p>
  
  <pre><code>angular.module('App').factory('socket', function ($rootScope) {
      'use strict';
          var socket = io.connect('http://localhost:3000');
          return {
              on: function (eventName, callback) {
                  socket.on(eventName, function () {
                      var args = arguments;
                      $rootScope.$apply(function () {
                          callback.apply(socket, args);
                      });
                  });
              },
              emit: function (eventName, data, callback) {
                  socket.emit(eventName, data, function () {
                      var args = arguments;
                      $rootScope.$apply(function () {
                          if (callback) {
                              callback.apply(socket, args);
                          }
                      });
                  })
              }
          };
  
  });
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>var io = require('socket.io')(server);
    io.sockets.on('connection',function(){
     // Producer.startProducer();
      ditconsumer.start(function(value){
          io.emit('ditConsumer',value)
      });
      io.sockets.on('end', function() {
          socket.disconnect();
          console.log('it will disconnet connection');
      });
  });
  </code></pre>