title: socket.emit in a simple TCP Server written in NodeJS?
body: <p>[as you'll see, I don't understand the basic concepts of a TCP server and client very well and probably socket.emit is not even possible, but I'd like to know the best alternative or similar thing...]</p>
  
  <p>Socket.io has a beautiful thing to emit events and catch them on the other side, it's in it's first page (http://socket.io). Can I do something similar like that but with NodeJS' regular 'net' module ? If not then what's the equivalent ?</p>
  
  <p>I tried:</p>
  
  <p>server.js</p>
  
  <pre><code>var server = net.createServer(function(socket) {
      socket.on("connect",function() {
          socket.emit('test',{msg : 'did you get it ?'});
      });
  }).listen(8000);
  </code></pre>
  
  <p>client.js</p>
  
  <pre><code>var client = net.createConnection(8000, localhost);
  client.on('connect',function(){
      client.on('test',function(data) {
          console.log(data.toString());
      });
  });
  </code></pre>
  
  <p>But as you can imagine, it does not work. How can I achieve this ?</p>
  
  <p>Thanks in advance.</p>