Difference between revisions of "Peer-socket.as"
m |
m |
||
| Line 18: | Line 18: | ||
// Decode incoming message | // Decode incoming message | ||
socket.onData = function( data ) { | socket.onData = function( data ) { | ||
| + | echo( 'Message received:', '00ff00' ); | ||
echo( data, 'ffff00' ); | echo( data, 'ffff00' ); | ||
}; | }; | ||
| Line 23: | Line 24: | ||
// Send a message to the associated peer | // Send a message to the associated peer | ||
function sendMessage( content ) { | function sendMessage( content ) { | ||
| + | echo( 'Sending message: "'+content+'" to local peer', '00ff00' ); | ||
_root.socket.send( content + String.fromCharCode(13,10,13,10) ); | _root.socket.send( content + String.fromCharCode(13,10,13,10) ); | ||
} | } | ||
Revision as of 10:10, 26 March 2006
// Establish a connection with Gir (wikid.pl) // - Gir will spawn a dedicated peerd child in response to a valid connection request socket = new XMLSocket();
// Connect to our host to establish stream if ( socket.connect( 'organicdesign.co.nz', 1729 ) ) echo( 'connecting...', '00ff00' ); else echo( 'connect failed!', 'ff0000' );
// When connected, send login info socket.onConnect = function( success ) { if ( success ) { echo( 'onConnect succeeded!', '00ff00' ); sendMessage( 'Hello?' ); } else echo( 'onConnect failed!', 'ff0000' ); };
// Decode incoming message socket.onData = function( data ) { echo( 'Message received:', '00ff00' ); echo( data, 'ffff00' ); };
// Send a message to the associated peer function sendMessage( content ) { echo( 'Sending message: "'+content+'" to local peer', '00ff00' ); _root.socket.send( content + String.fromCharCode(13,10,13,10) ); }
function echo( txt, col ) { txt = _root.page.htmlText + "\n" + ''+txt+''; _root.page.htmlText = txt; }



