Permalink
Browse files

rewrote the readme to cut it down length-wise and bumped an example t…

…o near the top
  • Loading branch information...
1 parent 0b1f2d4 commit e583e4f1c09d316c3df4d31bf386e2d307572b77 @substack committed Feb 27, 2011
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,36 +0,0 @@
-#!/usr/bin/env node
-var DNode = require('dnode');
-
-// server:
-var server = DNode(function (client) {
- // Poll the client's own temperature() in celsius and convert that value to
- // fahrenheit in the supplied callback
- this.clientTempF = function (cb) {
- client.temperature(function (degC) {
- var degF = Math.round(degC * 9 / 5 + 32);
- cb(degF);
- });
- };
-}).listen(6060);
-
-// client:
-server.on('ready', function () {
- // The ready event is only necessary to avoid an initialization race
- // condition since the server might not be ready by the time the client
- // connects.
- DNode({
- // Compute the client's temperature and stuff that value into the callback
- temperature : function (cb) {
- var degC = Math.round(20 + Math.random() * 10 - 5);
- console.log(degC + '° C');
- cb(degC);
- }
- }).connect(6060, function (remote) {
- // Call the server's conversion routine, which polls the client's
- // temperature in celsius degrees and converts to fahrenheit
- remote.clientTempF(function (degF) {
- console.log(degF + '° F');
- // server.end(); // kills the server
- });
- });
-});
@@ -0,0 +1,21 @@
+var dnode = require('dnode');
+
+var client = dnode({
+ // Compute the client's temperature and stuff that value into the callback
+
+ temperature : function (cb) {
+ var degC = Math.round(20 + Math.random() * 10 - 5);
+ console.log(degC + '° C');
+ cb(degC);
+ }
+});
+
+client.connect(6060, function (remote, conn) {
+ // Call the server's conversion routine, which polls the client's
+ // temperature in celsius degrees and converts to fahrenheit
+
+ remote.clientTempF(function (degF) {
+ console.log(degF + '° F');
+ conn.end(); // all done!
+ });
+});
@@ -0,0 +1,12 @@
+var dnode = require('dnode');
+
+dnode(function (client) {
+ // Poll the client's own temperature() in celsius and convert that value to
+ // fahrenheit in the supplied callback
+ this.clientTempF = function (cb) {
+ client.temperature(function (degC) {
+ var degF = Math.round(degC * 9 / 5 + 32);
+ cb(degF);
+ });
+ };
+}).listen(6060);
View
0 examples/nested.js 100755 → 100644
No changes.
View
@@ -1,29 +0,0 @@
-#!/usr/bin/env node
-var DNode = require('../lib/dnode');
-var sys = require('sys');
-
-// server-side:
-var server = DNode({
- timesTen : function (n,reply) { reply(n * 10) },
- moo : function (reply) { reply(100) },
- sTimesTen : DNode.sync(function (n) { return n * 10 }),
-}).listen(6060);
-
-
-// client-side:
-server.on('ready', function () {
- // The server might not be ready yet since client and server are in the same
- // file for this example.
- DNode.connect(6060, function (remote) {
- remote.moo(function (x) {
- sys.log(x);
- });
- remote.sTimesTen(5, function (m) {
- sys.puts(m); // 50, computation executed on the server
- remote.timesTen(m, function (n) {
- sys.puts(n); // 50 * 10 == 500
- server.end(); // shut the server down after the client is done
- });
- });
- });
-});
@@ -0,0 +1,7 @@
+var dnode = require('dnode');
+
+dnode.connect(7070, function (remote) {
+ remote.zing(33, function (n) {
+ console.log('n = ' + n);
+ });
+});
@@ -0,0 +1,6 @@
+var dnode = require('dnode');
+
+var server = dnode({
+ zing : function (n, cb) { cb(n * 100) }
+});
+server.listen(7070);

0 comments on commit e583e4f

Please sign in to comment.