Skip to content

Instantly share code, notes, and snippets.

@DexterHaslem
Created September 23, 2013 19:43
Show Gist options
  • Save DexterHaslem/6675863 to your computer and use it in GitHub Desktop.
Save DexterHaslem/6675863 to your computer and use it in GitHub Desktop.
//
var net = require('net');
var client = net.connect({host: "127.0.0.1", port: 36973},
function()
{
subscribe(client, 'ES 12-13', true)
}
);
client.on('data', function(data)
{
ati_chunks(data).forEach(function(v)
{
console.log('chunk = ' + v);
})
});
client.on('end', function()
{
console.log(' -> disconnected')
});
function ati_chunks(data)
{
var chunks = [];
var lastStart = 0;
var numChunks = 0;
for (var i = 0; i < data.length; i++)
{
if (data[i] == 0)
{
var str = "";
for (var c = lastStart; c < i; c++)
str += String.fromCharCode(data[c]);
chunks.push();
chunks[numChunks++] = str;
lastStart = i+1;
}
}
return chunks;
}
function subscribe(sock, symbol, subscribe)
{
sock.write('4\0');
sock.write(symbol + '\0');
if (subscribe)
{
sock.write('1\0');
}
else
{
sock.write('0\0');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment