first commit

This commit is contained in:
2020-01-07 22:32:17 +01:00
commit 2b9fbb2431
5 changed files with 102 additions and 0 deletions

32
router.js Normal file
View File

@@ -0,0 +1,32 @@
const zmq = require('zeromq');
const address = 'tcp://127.0.0.1:12345';
const net = require('net');
const keyPair = zmq.curveKeyPair();
let router = new zmq.Router({
curveServer: false,
curvePublicKey: keyPair.publicKey,
curveSecretKey: keyPair.secretKey,
curveServerKey: '&WMz:eOrkJE@OO}5Lm?hcE:L:NZX9mGUGkFMCVyd'
});
const listen = async () => {
for await (const [sender, msg] of router) {
console.log("received: %s", Buffer.from(sender).toString('base64'), msg.toString());
setTimeout(() => {
let n = Math.ceil(Math.random() * 50) - 10;
router.send([sender, "hoi12345#"]);
}, 100);
}
}
const listenForEvents = async () => {
for await (event of router.events) {
console.log(`${event.type} ${JSON.stringify(event)}`)
}
}
const run = async () => {
await router.bind(address);
await Promise.all([
listen(),
listenForEvents()
]);
};
run();