// ZMQ fun socket.bind(portPub, function (err) { if (err) throw err; console.log(`bound to ${portPub}`); });
// Listen for message, then parse and broadcast it reqSocket.on('message', (msg) => { const message = parseMessage(msg) bridgeObject.onReqMessage(message[0], message[1], message[2]) })
fs.watch(filename, () => { publisher.send(JSON.stringify({ type: 'changed', file: filename, timestamp: Date.now() })); });
/** * Used to send a message to the Python process. * @param {Object} interProcessObject The standard inter-process object. * @return {None} */ const sendToPython = (interProcessObject, verbose) => { if (verbose) { console.log(`<- out ${JSON.stringify(interProcessObject)}`); } if (socket) { socket.send(JSON.stringify(interProcessObject)); } }
sub.on('message', json => { const msg = JSON.parse(json); const date = new Date(msg.timestamp); console.log(`File "${msg.file}" changed at ${date}`); });
// Get SUB ports from args subPorts.forEach(p => { console.log(`Subscribing to ${p}`); // Connect SUB ports to the PUB sockets of the other instances of our application subSocket.connect(`tcp://127.0.0.1:${p}`); });
process.on('SIGINT', () => { responder.close(); console.log('Bye !'); });
subSocket.on("message", msg => { // We start listening for messages that arrive at our SUB socket, // we do some simple parsing of the message to remove the chat prefix, // and then we broadcast it to all the clients connected to the current WebSocket server console.log(`From other server: ${msg}`); broadcast(msg.toString().split(" ")[1]); });
pullSocket.on('message', (msg) => { const message = parseMessage(msg) bridgeObject.onPullMessage(message[0], message[1], message[2]) requestEvents.emit(message[0], message[1], message[2]) })
sock.on('message', function(topic, message) { console.log('received a message related to:', topic.toString(), 'containing message:', message.toString('hex')); });
ws.on("message", msg => { // When a new message is received by our WebSocket, // we broadcast it to all the connected clients console.log(`Message: ${msg}`); broadcast(msg); // we also publish it through our PUB socket using chat as aprefix followed by a space, // so the message will be published to all the // subscriptions using chat as a filter pubSocket.send(`chat ${msg}`); });
requester.on('message', data => { console.log('Response : ', JSON.parse(data)); });
publisher.bind('tcp://*:60400', err => { if (err) { throw err; } console.log('Listening for zmq subscribers....'); });