Blog

  • Home /
  • Blog /
  • Taking Baby Steps with Node.js–Creating TCP Servers

Taking Baby Steps with Node.js–Creating TCP Servers

April 29, 2011

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 :-).

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be