title: Creating a TCP Socket in AngularJS
body: <p>In PHP it is easy to create, connect an interact with a TCP socket (<a href="http://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP" rel="nofollow">http://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP</a>, the Client part).</p>
  
  <p>How can I accomplish this in AngularJS?
  Tried the module on following site: <a href="https://github.com/BHSPitMonkey/angular-net-sockets" rel="nofollow">https://github.com/BHSPitMonkey/angular-net-sockets</a>, but failed. An example on this site would have been helpful to me.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>How can I use that in my controller? I'm getting the error: 'factory must return a value'.</p>
  
  <p>This is what I am trying to accomplish:</p>
  
  <pre><code>app.controller('controller', ['$scope', 'netsockets',  function ($scope, netsockets) {
  $scope.username = "test";
  
  $scope.send_socket = function(){
      socket.connect('1.1.1.1','1111');
      socket.sendData('hello world');
      socket.disconnect();
      socket.close();
  };
  </code></pre>
  
  <p>}]);</p>
  
  <p>This is my factory:</p>
  
  <pre><code>factory('netsockets', function(NetSocket) {
      return {
      init: function(){
          var socket = new NetSocket({
            onConnect: function(){
                alert('I\'m connected!');
            },
            onDisconnect: function(){
                alert('I\'m disconnected!');
            }
          });
      }
  }
  });
  </code></pre>