title: Closing a WebSocket properly
body: <p>When I close the <code>websocket(ws.$close())</code> in my AngularJS application it takes about 40 seconds until it actually closes and I receive the <code>onclose</code> event.  am using the <a href="https://github.com/wilk/ng-websocket" rel="nofollow">ng-websocket library</a>. Simple test code for example:</p>
  
  <pre><code>angular.module("mainModule").controller("mainController", function ($scope, $http, $websocket, $rootScope) {
      $scope.dataImage = "#";
      $scope.webSocket = null;
  
      $scope.testWebSocket = function () {
          $scope.webSocket = $websocket.$new({
              url: 'ws://someurl',
              reconnect: true
          });
  
          $scope.webSocket.$on('$message', $scope.imageArrived);
      }
  
      $scope.closeWebSocket = function () {
          $scope.webSocket.$un('$message');
          $scope.webSocket.$close();
          $scope.dataImage = "#";
      }
  
      $scope.imageArrived = function (imageMessage) {
          console.log("image arrived");
          $scope.dataImage = "data:image/gif;base64," + imageMessage.Data;
          $rootScope.$apply();
      }
  });
  </code></pre>
  
  <p>I created a WPF test application also using websockets and there I receive the <code>onclose</code> event immediately. Is there a way to speed up closing of the websocket?</p>