Created
January 27, 2016 23:42
-
-
Save battlecow/75835bb2085acacfbcf4 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
function sendTestRequest($id) { | |
$socket = new \ZMQSocket(new \ZMQContext(), \ZMQ::SOCKET_REQ); | |
$socket->connect("tcp://192.168.98.142:5668"); | |
$socket->send(json_encode(array("event" => 'test', "data" => $id)), \ZMQ::MODE_DONTWAIT); | |
$response = $socket->recv(); | |
$parsedResponse = json_decode($response); | |
return $parsedResponse; | |
} | |
for ($i = 0; $i <= 10; $i++) { | |
$response = sendTestRequest($i); | |
echo "$i ---> $response\n"; | |
} |
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 characters
var zmq = require('zmq'); | |
var zmqResponder = zmq.socket('rep'); | |
zmqResponder.on('message', function (msg, data) { | |
var parsed = JSON.parse(msg); | |
console.info('ZMQ Request received: ' + parsed.event); | |
setTimeout(function () { | |
console.log('received: ' + parsed.data); | |
zmqResponder.send(JSON.stringify('Message ID: ' + parsed.data)); | |
}, (Math.floor(Math.random() * (10 - 5 + 1)) + 5) * 1000); | |
}); | |
zmqResponder.bind('tcp://*:5668', function (err) { | |
if (err) { | |
console.error(err); | |
} else { | |
console.info("ZMQ awaiting orders on port 5668"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment