Skip to content

Instantly share code, notes, and snippets.

@jameshilliard
Created July 27, 2016 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshilliard/385de9d6b029dacd72a8248ecbdcd5c6 to your computer and use it in GitHub Desktop.
Save jameshilliard/385de9d6b029dacd72a8248ecbdcd5c6 to your computer and use it in GitHub Desktop.
function send(cmd) {
net = require('net')
var self = this
var fp = "/opt/ninjadb/listener"
var send_sep = '.';
var fld_sep = String.fromCharCode(9);
var val_sep = "=";
var msg = cmd;
console.log('send', cmd);
msg = msg
var sock = net.connect(fp, function(err) {
if (err) {
console.log('ckdb connection error');
return err
}
sock.setKeepAlive(true)
// write the length
var len = msg.length
var l = new Buffer(4)
l.writeUInt32LE(len)
sock.write(l)
// then write the actual message
var buf = new Buffer(msg)
sock.write(buf)
})
sock.on('error', function(err) {
console.log('socket error');
return err
})
sock.on('data', function(chunk) {
var len = chunk.readUInt32LE(0)
var out = chunk.slice(4, chunk.length)
console.log("response: " + out.toString());
return out
})
}
console.log(send("setopts.1.oc_BlocksPageSize.value=1000\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment