What is the difference between dnode and nowjs?

How do they compare to each other?

+44
javascript nowjs dnode
Mar 15 '11 at 19:58
source share
3 answers

TL DR

DNode

  • Provides RMI
  • remote functions can take callbacks as arguments;
  • which is good because it is completely asynchronous;
  • works autonomously or through an existing http-server;
  • may have a browser and Node clients;
  • supports middleware like connect ;
  • has been longer than NowJS.

Nowjs

  • goes beyond just RMI and implements a shared API. I like Dropbox , only with variables and functions instead of files;
  • remote functions also receive callbacks ( thanks to Shridatta and Eric from NowJS for clarification );
  • Depends on the operation of the HTTP listening server;
  • only browser clients can have;
  • became public just recently;
  • now incorrect.

Conclusion

NowJS is more like a toy right now - but keep the watch when it matures. For serious stuff, maybe with DNode. A more detailed overview of these libraries, read together.

DNode

DNode provides a remote method call structure. Both the client and server can expose functions to each other.

 // On the server var server = DNode(function () { this.echo = function (message) { console.log(message) } }).listen(9999) // On the client dnode.connect(9999, function (server) { server.echo('Hello, world!') }) 

The function that is passed to DNode() is a handler that is not like the one passed to http.createServer . It has two parameters: client can be used to access functions exported by the client, and connection can be used to handle connection-related events:

 // On the server var server = DNode(function (client, connection) { this.echo = function (message) { console.log(message) connection.on('end', function () { console.log('The connection %s ended.', conn.id) }) } }).listen(9999) 

Exported methods can be passed as you like, including functions. They are properly wrapped as a DNode proxy and can be called back to another endpoint. This is basic: DNode is completely asynchronous; it does not block while waiting for the remote method:

 // A contrived example, of course. // On the server var server = DNode(function (client) { this.echo = function (message) { console.log(message) return 'Hello you too.' } }).listen(9999) // On the client dnode.connect(9999, function (server) { var ret = server.echo('Hello, world!') console.log(ret) // This won't work }) 

Callbacks must be passed to receive responses from another endpoint. Complex conversations can become unreadable quite quickly. This question discusses possible solutions to this problem.

 // On the server var server = DNode(function (client, callback) { this.echo = function (message, callback) { console.log(message) callback('Hello you too.') } this.hello = function (callback) { callback('Hello, world!') } }).listen(9999) // On the client dnode.connect(9999, function (server) { server.echo("I can't have enough nesting with DNode!", function (response) { console.log(response) server.hello(function (greeting) { console.log(greeting) }) }) }) 

The DNode client can be scripted inside an instance of Node, or it can be embedded in a web page. In this case, it will only connect to the server that served on the web page. Connect has a lot of help in this case. This script has been tested with all modern browsers and with Internet Explorer 5.5 and 7.

DNode was launched less than a year ago, in June 2010. It has matured as a Node library can be. In my tests, I did not find obvious problems.

Nowjs

NowJS provides a kind of magical API that borders on sympathy. The server has everyone.now scope. Everything that is placed inside everyone.now becomes visible to every client through the now area.

This code on the server will share the echo function with each client that writes the message to the server console:

 // Server-side: everyone.now.echo = function (message) { console.log(message) } // So, on the client, one can write: now.echo('This will be printed on the server console.') 

When the "general" function is executed on the server side, this will have the now attribute, which is typical for the client who made this call.

 // Client-side now.receiveResponse = function (response) { console.log('The server said: %s') } // We just touched "now" above and it must be synchronized // with the server. Will things happen as we expect? Since // the code is not multithreaded and NowJS talks through TCP, // the synchronizing message will get to the server first. // I still feel nervous about it, though. now.echo('This will be printed on the server console.') // Server-side: everyone.now.echo = function (message) { console.log(message) this.now.receiveResponse('Thank you for using the "echo" service.') } 

Functions in NowJS can have return values. To get them, the callback must have passed:

 // On the client now.twice(10, function (r) { console.log(r) } // On the server everyone.now.twice = function(n) { return 2 * n } 

It matters if you want to pass the callback as an honest argument (not to collect the return value) - you must always pass the return value collector or Now JJ may get confused. According to the developers, this way of getting the return value with an implicit callback is likely to change in the future:

 // On the client now.crunchSomeNumbers('compute-primes', /* This will be called when our prime numbers are ready to be used. */ function (data) { /* process the data */ }, /* This will be called when the server function returns. Even if we didn't care about our place in the queue, we'd have to add at least an empty function. */ function (queueLength) { alert('You are number ' + queueLength + ' on the queue.') } ) // On the server everyone.now.crunchSomeNumbers = function(task, dataCallback) { superComputer.enqueueTask(task, dataCallback) return superComputer.queueLength } 

And this is for the NowJS API. Well, actually there are three more functions that can be used to detect client connectivity and disconnect. I do not know why, however, they did not display these functions using an EventEmitter .

Unlike DNode, NowJS requires the client to have a script running inside a web browser. The page containing the script must be served by the same Node that the server is running.

On the server side, NowJS also needs to listen on the HTTP server. It must be accepted when initializing NowJS:

 var server = http.createServer(function (req, response) { fs.readFile(__dirname + '/now-client.html', function (err, data) { response.writeHead(200, {'Content-Type':'text/html'}) response.write(data) response.end() }) }) server.listen(8080) var everyone = now.initialize(server) 

The first fix for NowJS is a couple of weeks ago (March 2011). So be a buggy. I myself found questions when writing this answer. We also expect the API to change a lot.

On the plus side, developers are very accessible - Eric even led me to create callbacks. The source code is not documented, but, fortunately, is simple and short, and the user manual and examples are enough to get started.

+61
Mar 16 '11 at 3:12
source share
— -

NewJS team member here. Correction of the answer andref:

NowJS fully supports the "Remote Method Call" . You can pass functions as arguments in remote calls, and you can also have functions as return values.

These functions are wrapped by NowJS in the same way as they are in DNode, so that they are executed on the machine on which the function was defined. This makes it easy to discover new features at the remote end, as in DNode.

PS Also, I don't know if andref means that remote calls are only asynchronous for DNode. Remote calls are also asynchronous in NowJS. They do not block your code.

+14
Mar 16 '11 at 10:21
source share

Did not try Dnode, so my answer is not comparable. But I would like to do some experiments using nowjs.

Nowjs is based on socket.io , which is pretty tricky . I often experience session timeouts, it disconnects and now.ready triggering events several times in a short time. Check out this issue on the nowjs github page.

I also found that network files are unstable on some platforms, but this can be circumvented by explicitly disabling websites.

I planned to create a production application using nowjs, but it seems that it is not mature enough to be usable. I will try dnode if it serves my purpose, otherwise I will switch to regular express .

Update:

Nows it seems to be canceled. Without fixation from 8 months.

+2
Apr 26 '12 at 5:13
source share



All Articles