var http = require('http'); 
var io = require('socket.io');
var url = require('url');  
var path = require('path'); 
var fs = require('fs');
var jQuery = require("jquery");

server = http.createServer(function(request, response){ 
    var uri = url.parse(request.url).pathname;
    if (uri === '/') {
        var filename = path.join(process.cwd(), 'index.html');
    } else {
        var filename = path.join(process.cwd(), uri);
    }
    path.exists(filename, function(exists) {  
        if (!exists) {  
            response.writeHead(404, {"Content-Type": "text/plain"});  
            response.write("404 Not Found\n");  
            response.end();  
            return;  
        }  
  
        fs.readFile(filename, "binary", function(err, file) {  
            if (err) {  
                response.writeHead(500, {"Content-Type": "text/plain"});  
                response.write(err + "\n");  
                response.end();  
                return;  
            }  
  
            response.writeHead(200);  
            response.write(file, "binary");  
            response.end();  
        });  
    });  
});
server.listen(8002);
  
// socket.io 
var socket = io.listen(server);

var socketClients = [];

socket.on('connection', function(client) {
    client.identifier = socketClients.length;
    socketClients.push(client);
    console.log("New client " + client.identifier + " connected, client list is now", socketClients.length);

    client.on('message', function(data) {
        console.log("Got message from client " + client.identifier, data);

        jQuery.each(socketClients, function(index, socketClient) {
            if (socketClient == client) {
                
                socketClient.send("Pong client " + socketClient.identifier);
                return true;
            }
            console.log("Forwarding data to " + socketClient.identifier);
            socketClient.send(data);
        });
    });

    client.on('disconnect', function() {
        socketClients = jQuery.grep(socketClients, function(value) {
            return value != client;
        });

        console.log("Client " + client.identifier + " disconnected, client list is now", socketClients.length);
    }) 
});

@@ -159,16 +159,46 @@
 ire(
-%22
+'
 jquery
-%22
+');%0Avar redis = require('redis'
 );%0A%0A
@@ -1172,18 +1172,151 @@
 (8002);%0A
-  
+%0A// REDIS%0Avar redisClient = redis.createClient();%0A%0AredisClient.on('error', function (err) %7B%0A    console.log('Redis error ' + err);%0A%7D);%0A
 %0A// sock
@@ -1619,324 +1619,1871 @@
     
-client.on('message', function(data) %7B%0A        console.log(%22Got message from client %22 + client.identifier, data);%0A%0A        jQuery.each(socketClients, function(index, socketClient) %7B%0A            if (socketClient == client) %7B%0A                %0A                socket
+// Send current data from Redis%0A    redisClient.hkeys('anon-ontologies', function(err, ontologies) %7B%0A        ontologies.forEach(function(ontology, i) %7B%0A            redisClient.lrange('anon-' + ontology, 0, -1, function(err, anonItems) %7B%0A                anonItems.forEach(function(anonItem, i) %7B%0A                    console.log(anonItem);%0A                    client.send(JSON.parse(anonItem));%0A                %7D);%0A            %7D);%0A        %7D);%0A    %7D);%0A    redisClient.hkeys('ontologies', function(err, ontologies) %7B%0A        ontologies.forEach(function(ontology, i) %7B%0A            redisClient.hkeys(ontology, function(err, itemIdentifiers) %7B%0A                itemIdentifiers.forEach(function(itemIdentifier, i) %7B%0A                    redisClient.hget(ontology, itemIdentifier, function(err, item) %7B%0A                        console.log(item);%0A                        client.send(JSON.parse(item));%0A                    %7D);%0A                %7D);%0A            %7D);%0A        %7D);%0A    %7D);%0A%0A    client.on('message', function(data) %7B%0A        console.log(%22Got message from client %22 + client.identifier, data);%0A        %0A        if (typeof data === 'object') %7B%0A            if (data%5B'a'%5D !== undefined) %7B%0A                if (data%5B'@'%5D !== '%3Cundefined%3E') %7B%0A                    // Identified object, save to Redis hash based on type%0A                    redis
 Client.
+h
 se
-nd(%22Pong client %22 + socketClient.identifier);
+t(data%5B'a'%5D, data%5B'@'%5D, JSON.stringify(data));%0A                    redisClient.hset('ontologies', data%5B'a'%5D, true);%0A                %7D else %7B%0A                    // Anonymous entity, save to Redis list based on type%0A                    redisClient.lpush('anon-' + data%5B'a'%5D, JSON.stringify(data));%0A                    redisClient.hset('anon-ontologies', data%5B'a'%5D, true);%0A                %7D%0A            %7D%0A        %7D%0A%0A        jQuery.each(socketClients, function(index, socketClient) %7B%0A            if (socketClient == client) %7B
 %0A   
@@ -3596,16 +3596,17 @@
 ifier);%0A
+%0A
         

Make our RDFa persistent via Redis