Difference between revisions of "Livelets.as"
(start from peer-socket.as) |
({{as}}) |
||
| Line 1: | Line 1: | ||
| − | // | + | // Extension:Livelets{{as}}{{#security:*|dev}}{{#security:view|*}} |
| − | // - See http://www.mediawiki.org/wiki/Extension: | + | // - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details |
// - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | // - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | ||
// | // | ||
Revision as of 00:04, 5 May 2007
// Extension:LiveletsTemplate:As{{#security:*|dev}}{{#security:view|*}} // - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details // - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) //
socket = new XMLSocket(); socket.connected = false; CRLF = String.fromCharCode(13,10,13,10);
// Connect to our host to establish stream socket.peerConnect = function( domain, port ) { if ( socket.connect( domain, port ) ) echo( 'Connecting to '+domain+':'+port, 'ffffff' ); else echo( 'Could not initialise connection!', 'ff0000' ); };
// When connected, send login info socket.onConnect = function( success ) { if ( this.connected = success ) { echo( 'Connected.', '00ff00' ); // request a dedicated peerd child spawn to handle this stream this.request( '/connect/peer/interface' ); } else { echo( 'Connection failed!', 'ff0000' ); echo( 'Will retry soon...', 'ffffff' ); } };
// Decode incoming message socket.onData = function( data ) { echo( 'Message received:', '00ff00' ); echo( data, 'ffff00' ); };
socket.onClose = function() { this.connected = false; echo( 'Connection closed!', 'ff0000' ); this.ctr = 1; echo( 'Will retry soon...', 'ffffff' ); };
socket.reduce = function() { if ( !this.connected && ++this.ctr % 250 == 1 ) this.peerConnect( 'organicdesign.co.nz', 1729 ); };
// Send a message to the associated peer socket.request = function( request ) { echo( 'Sending message: "' + request + '"', 'ffffff' ); _root.socket.send( 'GET ' + request + ' HTTP/1.1' + CRLF ); };
// needed since socket isn't made with createSymbol()
reduction.push( socket );



