-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
29 lines (26 loc) · 820 Bytes
/
server.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
var context = require('zmq');
var pull_socket = context.createSocket('pull');
pull_socket.bind("tcp://127.0.0.1:5555", function(err){
if(err) throw err;
console.log("Pull socket bound");
});
var pub_socket = context.createSocket('publisher');
pub_socket.bind("tcp://127.0.0.1:5556", function(err){
if(err) throw err;
console.log("Publishing socket bound");
});
pull_socket.on("message", function(message){
console.log("message received: " + message.toString());
/*if (Math.random() * 1000 > 950) {
console.log("========== waiting ==========");
setTimeout(function(){
pub_socket.send(message);
console.log("message sent");
},5000);
} else {
pub_socket.send(message);
console.log("message sent");
}*/
pub_socket.send(message);
console.log("message sent");
});