Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.0.7

  • Loading branch information...
commit 5b3aff96c3412826f7395c2fd829e97c2b1508f7 1 parent 2714e4b
Tim authored
Showing with 44 additions and 5 deletions.
  1. +43 −1 README.md
  2. +1 −4 package.json
View
44 README.md
@@ -25,7 +25,7 @@ Yeah so to install is real easy.
or to access the rpc-socket executable install globally:
- npm install -g rpc-socket
+ npm install rpc-socket
### GIT
@@ -40,6 +40,7 @@ You might want to download and move to a folder of your choise and test it out.
### Basic usage.
+## Simple child_process.fork()
```javascript
@@ -70,3 +71,44 @@ You might want to download and move to a folder of your choise and test it out.
}
}
```
+
+## Uses with a cluster.
+
+```javascript
+
+ var cluster = require('cluster');
+ var http = require('http');
+ var numCPUs = require('os').cpus().length;
+ var p = require('../lib/protocols/process')
+
+ var numReqs = 0;
+
+ if(cluster.isMaster) {
+ // Fork workers.
+ for(var i = 0; i < numCPUs; i++) {
+
+ (new p(cluster.fork())).expose('numReqs', function(a) {
+
+ this.send('numReqs', numReqs++);
+ });
+ }
+
+ setInterval(function() {
+ console.log("numReqs =", numReqs);
+ }, 1000);
+ } else {
+
+ var rpc = new p(process);
+ // Worker processes have a http server.
+ http.Server(function(req, res) {
+ res.writeHead(200);
+ // Send message to master process
+ rpc.invoke('numReqs', [], function(err, result) {
+ //console.log('Error: ', err)
+ //console.log('Result: ', result);
+
+ res.end("hello world!\nOh and numReqs: " + result.numReqs + "\n");
+ })
+ }).listen(8000);
+ }
+```
View
5 package.json
@@ -1,6 +1,6 @@
{
"name": "rpc-socket",
- "version": "0.0.6",
+ "version": "0.0.7",
"description": "RPC like calling over different types of sockets",
"keywords": ["rpc", "json", "socket", "server", "client"],
"author": "Tim <flybyme@wiyc.info>",
@@ -8,9 +8,6 @@
"email": "bug@wiyc.info",
"url": "https://github.com/FLYBYME/rpc-socket"
},
- "bin": {
- "rpc-socket": "./bin/rpc-socket"
- },
"repository": {
"type": "git",
"url": "git://github.com/FLYBYME/rpc-socket.git"
Please sign in to comment.
Something went wrong with that request. Please try again.