XML Socket.as

From Organic Design wiki
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

<as> socket = new XMLSocket(); socket.port = 2012; socket.thisGuid = guid(); socket.thisPeer = null; // defined after first message from our peer socket.peers = []; socket.thisInterface = null; // known after peer known socket.incomingEvents = {}; socket.outgoingEvents = {}; socket.finishedEvents = {};

// Connect to our host to establish stream socket.connect( '127.0.0.1', socket.port );

// When connected to our peer, send out info socket.onConnect = function(success) { _root.socket.connected = success; sendMessage('port='+socket.port+'&add=interface&guid='+socket.thisGuid, ); };

// Decode incoming message socket.onData = function(data) { var msg = data.split("|"); var subject = msg[0]; var content = msg[1]; // split subject query-string and extract our peer and our name logAdd(subject); var qs = subject.split("&"); for (var i = 0; i < qs.length; i++) { var j = qs[i].split("="); if (j[0] == 'to') _root.socket.thisInterface = j[1]; if ((j[0] == 'from') && (_root.socket.thisPeer == null)) { var peer = _root.socket.thisPeer = j[1]; logAdd('My peer is '+peer); } if (j[0] == 'peers') { _root.socket.peers = j[1].split(','); _root.socket.peers.push(_root.socket.thisPeer); } } // Split content quey-string and execute each event (guid=time,cmd,parameters...) qs = content.split("&"); for (var i = 0; i < qs.length; i++) { var j = qs[i].split("="); if (_root.socket.finishedEvents[guid] == null) createEvent(j[1], j[0]); // parameters, [guid] } };

// Send a message to the associated peer.pl function sendMessage(subject, content) { logAdd('Sending ('+subject+')'); _root.socket.send(subject+"|"+content); // SWF automatically appends \x00 }

// _____________________________________________________________________________________________________________________ //

function guid() { return 'g'+(Math.random()+getTimer()); }

function parent(s) { return s.substr(0,s.lastIndexOf('.')); }

// Sends log output to its associated perl-peer for output // - use logPattern = ^\. to filter since they all start with ...guid function logAdd(entry) { } </as>