Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit of data

  • Loading branch information...
commit 01fb473a3817dccc8d6b0e5d856fc1023dfb45a8 1 parent bae39f5
Frans-Willem Hardijzer authored
55 examples/inprocess/IPCNodeTest.js
View
@@ -0,0 +1,55 @@
+var IPCNode=require("../../IPCNode").IPCNode;
+var sys=require("sys");
+
+var a=new IPCNode();
+var b=new IPCNode();
+
+sys.pump(a,b);
+sys.pump(b,a);
+
+var ipcobj={
+ msg: "",
+ set: function(s) { this.msg=s; },
+ get: IPCNode.sync(function() {
+ return this.msg;
+ }),
+ timerAsync: IPCNode.async(function(callback) {
+ setTimeout(function() { callback(); },1000);
+ }),
+ timerCustom: function(callback) {
+ var callbackRef=IPCNode.reference(callback);
+ setTimeout(function() {
+ callbackRef();
+ IPCNode.dispose(callbackRef);
+ },1000);
+ }
+};
+
+function demonstrate(obj,method) {
+ obj.set("Hello world");
+ obj.get(function(msg) {
+ sys.puts("Got message over "+method+": '"+msg+"'");
+ });
+ obj.timerAsync(function() {
+ sys.puts("timerAsync callback over "+method);
+ });
+ obj.timerCustom(function() {
+ sys.puts("timerCustom callback over "+method);
+ });
+}
+
+b.on("register",function(name,obj) {
+ if (name=="ipc")
+ demonstrate(obj,"IPC");
+});
+
+sys.puts("Demonstrating directly");
+demonstrate(ipcobj,"local");
+sys.puts("Demonstrating over IPCNode");
+a.register("ipc",ipcobj);
+a.on("clean",function() {
+ sys.puts("Server endpoint clean");
+});
+b.on("clean",function() {
+ sys.puts("Client endpoint clean");
+});
33 examples/sockets/IPCNodeClient.js
View
@@ -0,0 +1,33 @@
+var sys=require("sys");
+var net=require("net");
+var IPCNode=require("../../IPCNode").IPCNode;
+
+var client=net.createConnection(81234);
+var ipc=new IPCNode();
+client.on("connect",function() {
+ sys.pump(client,ipc,function() { ipc.end(); sys.puts("Connection closed"); });
+ sys.pump(ipc,client,function() { client.end(); client.destroy() });
+});
+client.on("error",function(e) {
+ sys.puts("Client error: "+e.toString());
+ ipc.end();
+});
+ipc.on("error",function(e) {
+ sys.puts("IPC error: "+e.toString());
+ client.end();
+});
+ipc.on("register",function(name,obj) {
+ sys.puts("Got object: "+name);
+ if (name=="main") {
+ //obj will be disposed once this method ends, so we need a copy for in the callback functions
+ var copy=IPCNode.reference(obj);
+ copy.increase();
+ copy.get_counter(function(i) {
+ copy.printString("Client number: "+i);
+ copy.printArray(["Hello","World"]);
+ copy.printSimpleObject({Hello: "World",How: "Are", You: "Today"});
+ //No longer using copy, so dispose it.
+ IPCNode.dispose(copy);
+ });
+ }
+});
56 examples/sockets/IPCNodeServer.js
View
@@ -0,0 +1,56 @@
+var net=require("net");
+var sys=require("sys");
+var IPCNode=require("../../IPCNode").IPCNode;
+
+//Main object being made available to the clients
+var mainObject={
+ counter: 0,
+ increase: function() {
+ this.counter++;
+ },
+ get_counter: IPCNode.sync(function() {
+ return this.counter;
+ }),
+ printString: function(msg) {
+ sys.puts("String: "+msg);
+ },
+ printArray: function(msgs) {
+ sys.puts("Array:");
+ for (var i=0; i<msgs.length; i++)
+ sys.puts("\t"+msgs[i]);
+ },
+ printSimpleObject: function(msgs) {
+ sys.puts("Object:");
+ for (var i in msgs)
+ sys.puts("\t"+i+": "+msgs[i]);
+ }
+};
+
+net.createServer(function(client) {
+ sys.puts("New connection");
+ client.on("connect",function() {
+ sys.puts("Connected");
+ var ipc=new IPCNode();
+ sys.pump(ipc,client,function() { ipc.end(); });
+ sys.pump(client,ipc,function() { client.end(); client.destroy(); });
+
+ ipc.on("error",function(e) {
+ sys.puts("IPC error: "+e.toString());
+ client.end();
+ client.destroy();
+ });
+ ipc.on("clean",function(from) {
+ sys.puts("IPC stream is clean, no more cross-process oject references");
+ ipc.end();
+ client.end();
+ client.destroy();
+ });
+
+ ipc.register("main",mainObject);
+ });
+ client.on("error",function(e) {
+ sys.puts("Client error: "+e.toString());
+ ipc.end();
+ });
+}).listen(81234);
+sys.puts("Listening on port 81234");
Please sign in to comment.
Something went wrong with that request. Please try again.