Created
July 8, 2018 04:08
-
-
Save oldmud0/bf78f27525f05faa07b8a9ef981f1f03 to your computer and use it in GitHub Desktop.
Revisions
-
oldmud0 created this gist
Jul 8, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ const ipc = require("node-ipc"); const async = require("async"); const queue = async.queue((data, cb) => { // There is no way of checking if client is connected so just // catch and put it back in the queue if a bad happens. try { ipc.of.test.emit("message", data); } catch (err) { console.error(err); queue.unshift(data); } cb(); }); queue.pause(); let i = 0; ipc.config.id = "test"; ipc.config.silent = true; setInterval(() => { console.log(`Buffered message ${i}`); queue.push(i++); }, 500); ipc.connectToNet("test", () => { ipc.of.test.on("connect", () => { console.log("connected"); queue.resume(); }); ipc.of.test.on("message", (data) => { console.log(data); }); ipc.of.test.on("error", (err) => { queue.pause(); }) }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ const ipc = require("node-ipc"); ipc.config.id = "test"; ipc.serveNet(() => { ipc.server.on("connect", () => { ipc.server.broadcast("message", "yoyooyoyoy"); }); ipc.server.on("message", (data, socket) => { ipc.server.emit(socket, "message", data); }); }); ipc.server.start();