title: How to create a simple socket in node.js?
body: <p>I'm trying to create a dummy socket for use in some of my tests</p>
  
  <pre><code>var net = require("net");
  
  var s = new net.Socket();
  
  s.on("data", function(data) {
    console.log("data received:", data);
  });
  
  s.write("hello!");
  </code></pre>
  
  <p>Getting this error</p>
  
  <blockquote>
    <p>Error: This socket is closed.</p>
  </blockquote>
  
  <p>I've also tried creating the socket with</p>
  
  <pre><code>var s = new net.Socket({allowHalfOpen: true});
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <p>For reference, the complete test looks like this</p>
  
  <pre><code>it("should say hello on connect", function(done) {
  
    var socket = new net.Socket();
  
    var client = Client.createClient({socket: socket});
  
    socket.on("data", function(data){
      assert.equal("hello", data);
      done();
    });
  
    client.connect();
    // writes "hello" to the socket
  });
  </code></pre>