Difference between revisions of "Peer-socket.as"

From Organic Design wiki
(oops hadn't saved this edit)
m
Line 4: Line 4:
  
 
// Connect to our host to establish stream
 
// Connect to our host to establish stream
if ( socket.connect( 'organicdesign.co.nz', 1729 ) ) echo( 'Connecting...', '00ff00' );
+
if ( socket.connect( 'organicdesign.co.nz', 1729 ) ) echo( 'Connecting...', 'ffffff' );
 
else echo( 'Could not initialise connection!', 'ff0000' );
 
else echo( 'Could not initialise connection!', 'ff0000' );
  
Line 10: Line 10:
 
socket.onConnect = function( success ) {
 
socket.onConnect = function( success ) {
 
if ( success ) {
 
if ( success ) {
echo( 'Connected!', '00ff00' );
+
echo( 'Connected.', '00ff00' );
 
sendMessage( 'Hello?' );
 
sendMessage( 'Hello?' );
 
}
 
}
Line 24: 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+'"', '00ff00' );
+
echo( 'Sending message: "'+content+'"', 'ffffff' );
 
_root.socket.send( content + String.fromCharCode(13,10,13,10) );
 
_root.socket.send( content + String.fromCharCode(13,10,13,10) );
 
}
 
}

Revision as of 02:46, 27 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...', 'ffffff' ); else echo( 'Could not initialise connection!', 'ff0000' );

// When connected, send login info socket.onConnect = function( success ) { if ( success ) { echo( 'Connected.', '00ff00' ); sendMessage( 'Hello?' ); } else echo( 'Connection 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+'"', 'ffffff' ); _root.socket.send( content + String.fromCharCode(13,10,13,10) ); }