first commit
This commit is contained in:
32
router.js
Normal file
32
router.js
Normal 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();
|
||||
Reference in New Issue
Block a user