-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
35 lines (29 loc) · 800 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const ipc = require("node-ipc");
const CUSTOM_EVENT = "app.message";
ipc.config.id = "bridge";
ipc.config.retry = 1500;
ipc.serve();
ipc.server.on(CUSTOM_EVENT, (msg, socket) => {
ipc.server.emit(socket, CUSTOM_EVENT, `${msg} world!`);
});
ipc.server.on("connect", (socket) => {
const timer = setInterval(() => {
ipc.server.emit(socket, CUSTOM_EVENT, "tick");
}, 10000);
socket.on("end", () => {
clearInterval(timer);
});
});
ipc.server.start();
// js ipc client
ipc.connectTo("bridge", () => {
ipc.of.bridge.on("connect", () => {
ipc.of.bridge.emit(CUSTOM_EVENT, "hello");
});
ipc.of.bridge.on("disconnect", () => {
ipc.log("disconnected from world");
});
ipc.of.bridge.on(CUSTOM_EVENT, (msg) => {
ipc.log("got a message from world : ", msg);
});
});