NodeJS

I came across Node. It is similar to Python Twisted, except it is JavaScript (JS) and all IO is non blocking. Imagine an echo server in five lines of code or a pass-thru in about twenty as shown below:

var net = require('net');

var client = net.connect({port: 7000},
                          function() { //'connect' listener
                               console.log('client connected');
                           }
                         );
var historianClient;
var s = net.createServer(function (socket) {
                           historianClient = socket;
                           historianClient.on('data', 
                           function (buffer) {
                                if(client != null)
                                {
                                  client.write(buffer);
                                  console.log('Historian:' + buffer.toString());
                               }
                           });
                        });

s.listen(7100);
client.on('data', function (buffer) {
                       if(historianClient != null){
                         historianClient.write(buffer);
                         console.log('SCADA:' + buffer.toString());
                       }
                   });

On Windows Node uses IOCompletion ports and V8 – Google’s JS engine that translates JS to native code. Javascript may not be the best language in town but its popularity makes the Node almost a necessity.

Advertisements

About The Sunday Programmer

Joe is an experienced C++/C# developer on Windows. Currently looking out for an opening in C/C++ on Windows or Linux.
This entry was posted in Software Engineering. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s