Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created June 2, 2015 18:46
Show Gist options
  • Save thelinuxlich/36290060a4bcda2aed79 to your computer and use it in GitHub Desktop.
Save thelinuxlich/36290060a4bcda2aed79 to your computer and use it in GitHub Desktop.
Server impl
"use strict";
const nano = require("nanomsg"),
req = nano.socket("req", {
reconn: 10,
linger: 1
});
req.bind("tcp://127.0.0.1:7000");
let count = 1;
const makeid = function() {
let text = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
},
sendMessage = function() {
const id = makeid();
console.log("Sending " + id);
req.send("test " + id);
count++;
},
timer = setInterval(function() {
if (count > 10) {
clearInterval(timer);
} else {
sendMessage();
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment