Difference between revisions of "Namecoin SPA"

From Organic Design wiki
m
m
Line 17: Line 17:
 
select $c;
 
select $c;
 
$|=1;
 
$|=1;
print $c "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\nConnection: Keep-Alive\nKeep-Alive: timeout=15, max=100\nContent-Length: $l\n\n$_\r\n\r\n";
+
print $c "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\n";
 +
print $c "Connection: Keep-Alive\nKeep-Alive: timeout=15, max=100\nContent-Length: $l\n\n$_\r\n\r\n";
 
close($c);
 
close($c);
 
exit(fork);
 
exit(fork);

Revision as of 21:23, 25 August 2012

I'm making a Single Page Application which exists entirely inside the Namecoin network's name:value storage system. Values can only be a maximum size of one kilobyte, so the boot-strapping has to be very modular.

The root node contains a tiny Perl script which when executed on the command-line listens for incoming HTTP connections on port 2012. The request is treated as a requst for the content of a Namecoin node, but if there is no name specified, then a default node's content is returned.

{{{1}}}


If any nodes are requested they'll usually just be some JSON text defining the nodes DNS connections to other IP addresses or domains. The default node's content is however not JSON, but a small XHTML document. This loads a simple container page that loads some useful libraries such as jQuery and jQueryUI, and then requests any node specified in the hash fragment of the URL by Ajax.

<xml><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

</xml>


If no hash fragment is specified, then a default node is used which contains JavaScript that gets executed (this only happens for this known default node, not for any arbitrary nodes). This JavaScript is the basic Single Page Application, or "viewer application" that knows how to render the DNS relationships between the nodes recirsively, so that further nodes can build up more complex applicational functionality.