var net = require('net');

var HOST = '127.0.0.1';
var PORT = 13854;


/* Network Socket to Thinkgear Connector */

var client = new net.Socket();

client.connect(PORT, HOST, function() {

    client.write('{"appName": "brain.json", "appKey": "9f54141b4b4c567c558d3a76cb8d715cbde03096", "format": "Json"}');

	// write session start
});


/* Receive Data */

client.on('data', function(data) {
	// save to database
	
	// * normal event
	// * blink event
	// * lost signal event
});


// Add a 'close' event handler for the client socket
client.on('close', function() {
	// write session end
});

@@ -64,16 +64,100 @@
 3854;%0A%0A%0A
+// TODO wrap this in a class with callbacks for handling the specific json events%0A%0A%0A
 /* Netwo
@@ -266,16 +266,93 @@
 on() %7B%0A%0A
+%09client.write(JSON.stringify(%7B%22enableRawOutput%22: false, %22format%22: %22Json%22%7D));%0A
     clie
@@ -360,17 +360,31 @@
 t.write(
-'
+JSON.stringify(
 %7B%22appNam
@@ -417,68 +417,50 @@
 : %229
-f54141b4b4c567c558d3a76cb8d715cbde03096%22, %22format%22: %22Json%22%7D'
+385e00cb35898fb8f551ae9b2d0d1824aaf481e%22%7D)
 );%0A%0A
@@ -567,16 +567,247 @@
 abase%0A%09%0A
+%09// For when two results come in the same packet%0A%09var rows = data.toString().split('%5Cr');%0A%0A%09// Remove trailing newline.%0A%09rows.pop();%0A%0A%09// Process Rows%0A%09rows.forEach( function(row) %7B%0A%09%09console.log(JSON.parse(row.toString()));%0A%09%7D);%0A%0A
 %09// * no

Split json messages on carraige returns.