29 Apr
2011

Taking Baby Steps with Node.js–Creating TCP Servers

Category:UncategorizedTag: :

Here are the links to the previous installments:

  1. Introduction
  2. Threads vs. Events
  3. Using Non-Standard Modules
  4. Debugging with node-inspector
  5. CommonJS and Creating Custom Modules
  6. Node Version Management with n
  7. Implementing Events
  8. BDD Style Unit Tests with Jasmine-Node Sprinkled With Some Should
  9. ?node_modules? Folders
  10. Pumping Data Between Streams
  11. Some Node.js Goodies
  12. The Towering Inferno

Just a quick post to show that although creating HTTP servers clearly dominates most code samples that demonstrate the use of Node.js, that it?s also possible to create TCP servers using Node.js.

var net = require(?net?);

net.createServer(function(socket)) {
    
    socket.on('data', function(data) {
        socket.write(data);
    });
    
}
.listen(2500);

This code sample isn?t very useful in and of itself except for the fact that it demonstrates that it?s just as easy to create a TCP server as it is to create an HTTP server with Node.js.

There! Feeling all better now :-).

Find me

RSS
Facebook
Twitter
LinkedIn
SOCIALICON
SOCIALICON

Disclaimer

The opinions and content expressed here are my own and not those of my employer.