Skip to content

Commit

Permalink
Merge pull request #21 from tst2005/missinglocalprefix
Browse files Browse the repository at this point in the history
Missing local prefix
  • Loading branch information
Overtorment authored Jul 28, 2016
2 parents eb4ac2c + 23d758c commit 3aad29a
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 150 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ START SERVER

INITIALIZE
```lua
hub = noobhub.new({ server = "127.0.0.1"; port = 1337; });
hub = noobhub.new({ server = "127.0.0.1"; port = 1337; });
```

SUBSCRIBE TO A CHANNEL AND RECEIVE CALLBACKS WHEN NEW JSON MESSAGES ARRIVE
```lua
hub:subscribe({
channel = "hello-world";
channel = "hello-world";
callback = function(message)
if(message.action == "ping") then

if(message.action == "ping") then
print("Pong!")
end;

end;
});
```
Expand Down
48 changes: 23 additions & 25 deletions client/javascript-node-js/client.benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var echo = (process.argv && process.argv[2] == 'echo')
, crypto = require('crypto')

, Trololo = new function() {

var host = 'localhost'
, port = '1337'
, self = this
Expand All @@ -14,61 +14,59 @@ var echo = (process.argv && process.argv[2] == 'echo')
, startTime = 0
, triesMax = 1000
, tryCurrent = 0
, stats = {
, stats = {
max: 0,
min: 10000,
average: 0,
data: []
};

this.send = function() {
console.log('[BENCHMARKING MODE]');
self._connectAndSubscribe(function(){
socket.on('data', self._measure);
self._ping();
});

}

this._ping = function() {

hash = String( Math.random() * 1000 );
console.log('sending hash ', hash);
startTime = new Date().getTime();
socket.write("__JSON__START__" + hash + "__JSON__END__");
}

this._measure = function(data) {
console.log('got data ', String(data));
console.log('got data ', String(data));

var str = String(data).replace(/__JSON__START__|__JSON__END__|\r|\n/g, '');

if (str == hash) {
if (str == hash) {
var lat = new Date().getTime() - startTime;
console.log('latency ', lat);
stats.data.push(lat);
var summ = 0;
if (++tryCurrent == triesMax) {

for (var i=0, l=stats.data.length; i<l; i++) {

if (stats.data[i] > stats.max) {
stats.max = stats.data[i]
}
}

if (stats.data[i] < stats.min) {
stats.min = stats.data[i]
}
summ += stats.data[i];
}

stats.average = Number(summ / triesMax).toFixed(2);

console.log('[RESULTS]');
console.log('max latency : ' + stats.max);
console.log('min latency : ' + stats.min);
console.log('average : ' + stats.average);

} else {
self._ping();
}
Expand All @@ -77,35 +75,35 @@ var echo = (process.argv && process.argv[2] == 'echo')
//console.log(str + " != " + hash);
}
}

this.listen = function() {
console.log('[ECHO MODE]');
self._connectAndSubscribe();

var lastResponse = null;
socket.on('data', function(data){

if (String(data) != String(lastResponse)) {
console.log('incoming data', data);
lastResponse = data;
socket.write("__JSON__START__" + data + "__JSON__END__");
}
})
}

this._connectAndSubscribe = function(cb) {
socket = new net.createConnection(port, host);
socket.setNoDelay(true);

socket.on('connect', function(){
console.log('connected to ', host, port);
console.log(arguments);

socket.write("__SUBSCRIBE__" + channel + "__ENDSUBSCRIBE__");

if (typeof(cb) == "function") cb();
})
}
}

echo ? Trololo.listen() : Trololo.send();
echo ? Trololo.listen() : Trololo.send();
2 changes: 1 addition & 1 deletion client/javascript-node-js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var Nbhb = exports.Nbhb = function() {
var s = String(str).replace(/}{|\r|\n/g, '}<splitHere>{');

if (s == str){

if (typeof(self.messageCallback) === "function")
self.messageCallback(str);
}
Expand Down
2 changes: 0 additions & 2 deletions client/javascript-node-js/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ noobhub.subscribe(
}
, function(s){
console.log('subscribed callback');

noobhub.publish({ a : Math.random() }, function(){
console.log("data sent");
});

}
, function(data) {
console.log("get data callback: " + data);
Expand Down
16 changes: 8 additions & 8 deletions client/javascript-node-js/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ var z = function(idx) {
server: 'localhost',
channel: channel
}, function() { isAlive = 1; return _onSubscribed(idx); }
, function(msg) {
, function(msg) {
if (msg === _myMessage) {
var lat = Date.now() - startTime;
console.log(idx + 'latency is : ', lat);
_sendMetrics('latency:'+lat+'|ms');
}
return _onMessage(idx, msg);
return _onMessage(idx, msg);
}
, function(err) {
isAlive = 0;
clearInterval(_interval);
clearInterval(_changeChannel);
, function(err) {
isAlive = 0;
clearInterval(_interval);
clearInterval(_changeChannel);
return _onError(idx, err);
}
);
Expand Down Expand Up @@ -93,7 +93,7 @@ var z = function(idx) {
clearInterval(_interval);
clearInterval(_changeChannel);
n.unsubscribe();
n = null;
n = null;
}
};

Expand All @@ -114,4 +114,4 @@ for (var i=0, l=config.zerlings; i<l; i++) {
(function(idx){
return z(idx);
}(i));
}
}
14 changes: 7 additions & 7 deletions client/javascript-node-js/perf_single_channel_load.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var zergsAlive = config.zerglings;

var _sendMetrics = function(msg) {
return false;


var cfg = config.statsd;
var message = new Buffer(cfg.prefix + msg);
Expand Down Expand Up @@ -63,18 +63,18 @@ var z = function(idx) {
server: 'localhost',
channel: channel
}, function() { isAlive = 1; return _onSubscribed(idx); }
, function(msg) {
, function(msg) {
if (msg === _myMessage) {
var lat = Date.now() - startTime;
console.log(idx + 'latency is : ', lat);
//_sendMetrics('latency:'+lat+'|ms');
}
return _onMessage(idx, msg);
return _onMessage(idx, msg);
}
, function(err) {
isAlive = 0;
clearInterval(_interval);
clearInterval(_changeChannel);
, function(err) {
isAlive = 0;
clearInterval(_interval);
clearInterval(_changeChannel);
return _onError(idx, err);
}
);
Expand Down
4 changes: 2 additions & 2 deletions client/lua-corona/noobhub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ noobhub = {

local got_something_new = false
while true do
skt, e, p = v:receive()
local skt, e, p = v:receive()
if (skt) then self.buffer = self.buffer .. skt; got_something_new=true; end
if (p) then self.buffer = self.buffer .. p; got_something_new=true; end
if (not skt) then break; end
Expand Down Expand Up @@ -137,4 +137,4 @@ noobhub = {

return self
end -- /new
}
}
Loading

0 comments on commit 3aad29a

Please sign in to comment.