Difference between revisions of "Peer-socket.as"

From Organic Design wiki
m
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 ) ) msg( 'connecting...', '00ff00', true );
+
if ( socket.connect( 'organicdesign.co.nz', 1729 ) ) echo( 'connecting...', '00ff00' );
else msg( 'connect failed!', 'ff0000', true );
+
else echo( 'connect failed!', 'ff0000' );
  
msg( 'dsafsafsafa', 'ffff00', true );
+
echo( 'dsafsafsafa', 'ffff00' );
  
 
// When connected, send login info
 
// When connected, send login info
 
socket.onConnect = function( success ) {
 
socket.onConnect = function( success ) {
 
if ( success ) {
 
if ( success ) {
msg( 'onConnect succeeded!', '00ff00', true );
+
echo( 'onConnect succeeded!', '00ff00' );
 
sendMessage( 'Hello?' );
 
sendMessage( 'Hello?' );
 
}
 
}
else msg( 'onConnect failed!', 'ff0000', true );
+
else echo( 'onConnect failed!', 'ff0000' );
 
};
 
};
  
 
// Decode incoming message
 
// Decode incoming message
 
socket.onData = function( data ) {
 
socket.onData = function( data ) {
msg( data, '0000ff', true );
+
echo( data, '0000ff' );
 
};
 
};
  
Line 28: Line 28:
 
}
 
}
  
function msg( txt, col, app ) {
+
function echo( txt, col ) {
 
txt = '<font color="#'+col+'">'+txt+'</font>';
 
txt = '<font color="#'+col+'">'+txt+'</font>';
 
//if ( app ) txt = _root.page.htmlText + "\n" + txt;
 
//if ( app ) txt = _root.page.htmlText + "\n" + txt;
 
_root.page.htmlText = 'txt';
 
_root.page.htmlText = 'txt';
 
}
 
}

Revision as of 07:53, 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' );

echo( 'dsafsafsafa', 'ffff00' );

// 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( data, '0000ff' ); };

// Send a message to the associated peer function sendMessage( content ) { _root.socket.send( content + String.fromCharCode(13,10,13,10) + content + String.fromCharCode(13,10) ); }

function echo( txt, col ) { txt = ''+txt+''; //if ( app ) txt = _root.page.htmlText + "\n" + txt; _root.page.htmlText = 'txt'; }