Difference between revisions of "Server-monitor.as"

From Organic Design wiki
m (x scale)
(begin integrating graph with socket code)
Line 1: Line 1:
// blank movie clip
+
#include "bar-graph.as"
createEmptyMovieClip( 'graph', 100 );
 
  
dither = 1;
 
  
for ( i = 0; i < 800; i += 1 ) {
+
// Establish a connection with perl server
if (dither == 1) { graph.lineStyle( 1, 0x00dd00 ); } else { graph.lineStyle( 1, 0x008800 ); }
+
socket = new XMLSocket();
dither = dither ^ 1;
+
 
graph.moveTo( i, height );
+
 
graph.lineTo( i, height/2 - ( Math.sin(i/30) * height/4 ) );  
+
createSymbol( this, 'barGraph', 'myGraph', 0 );
}
+
 
 +
// Connect to our host to establish stream
 +
if ( socket.connect( 'cs.auckland.ac.nz', 60180 ) ) echo( 'Connecting...', '00ff00' );
 +
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+'"', '00ff00' );
 +
    _root.socket.send( content + String.fromCharCode(13,10,13,10) );
 +
    }
 +
 
 +
function echo( txt, col ) {
 +
    txt = _root.page.htmlText + "\n" + '<font color="#'+col+'">'+txt+'</font>';
 +
    _root.page.htmlText = txt;
  
// Textbox
 
createTextField( 'rc', 1, 0, 0, width, height );
 
with (rc) {
 
_alpha = 30;
 
selectable = true;
 
_quality = 'BEST';
 
border = false;
 
multiline = true;
 
wordWrap = true;
 
html = true;
 
htmlText = '<font color="#00ff00">Hello World :-)</font>';
 
}
 
  
  
 
function reduce() {
 
function reduce() {
}
+
    myGraph.rotate( Math.sin( ++x/10 ) * height / 3 + height / 2 );
 +
    }

Revision as of 02:07, 27 March 2006

  1. include "bar-graph.as"


// Establish a connection with perl server socket = new XMLSocket();


createSymbol( this, 'barGraph', 'myGraph', 0 );

// Connect to our host to establish stream if ( socket.connect( 'cs.auckland.ac.nz', 60180 ) ) echo( 'Connecting...', '00ff00' ); 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+'"', '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;


function reduce() {

   myGraph.rotate( Math.sin( ++x/10 ) * height / 3 + height / 2 );
   }