Difference between revisions of "Peer-socket.as"
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 ) ) | + | if ( !socket.connect( 'organicdesign.co.nz', 1729 ) ) error( 'connect failed!' ); |
| − | |||
// When connected, send login info | // When connected, send login info | ||
socket.onConnect = function( success ) { | socket.onConnect = function( success ) { | ||
| − | if ( success ) | + | if ( success ) sendMessage( 'Hello?' ); else error( 'onConnect failed!' ); |
| − | |||
| − | |||
| − | |||
| − | |||
}; | }; | ||
// Decode incoming message | // Decode incoming message | ||
socket.onData = function( data ) { | socket.onData = function( data ) { | ||
| − | + | _root.page.htmlText = '<font color="#00ff00">'+data+'</font>'; | |
}; | }; | ||
| Line 26: | Line 21: | ||
} | } | ||
| − | function msg | + | function error( msg ) { |
| − | + | _root.page.htmlText = '<font color="#ff0000">'+msg+'</font>'; | |
| − | |||
| − | |||
} | } | ||
Revision as of 07:44, 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 ) ) error( 'connect failed!' );
// When connected, send login info socket.onConnect = function( success ) { if ( success ) sendMessage( 'Hello?' ); else error( 'onConnect failed!' ); };
// Decode incoming message socket.onData = function( data ) { _root.page.htmlText = ''+data+''; };
// 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 error( msg ) { _root.page.htmlText = ''+msg+''; }



