Created
June 2, 2015 18:46
-
-
Save thelinuxlich/36290060a4bcda2aed79 to your computer and use it in GitHub Desktop.
Server impl
This file contains 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
"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