// Copyright (c) 2007-2009 The PyAMF Project.
// See LICENSE for details.

// Load the Remoting classes
load("netservices.asc");

application.onAppStart = function() {
    // Setup connection
    NetServices.setDefaultGatewayUrl("http://localhost:8000");
    // Gateway connection object
    this.gateway = NetServices.createGatewayConnection();
}

application.onConnect = function( clientObj ) {
    // Create service object to access the remote service called 'echo',
    // and set responder property to the object that will receive the 
    // result or fault condition that the service returns.
    clientObj.service = this.gateway.getService("echo", new PyAMFResult( clientObj ) );

   // This var holds the data we want to pass to the remote service.
   var param = "Hello World!";

    // Call remote service to send data
    this.service.echo( param );

    // Accept the client connection
    this.acceptConnection( clientObj );
}

/**
 * Remoting Object.
 * Default responder object for Remoting calls.
 */
function PyAMFResult( client ) {
    // Set the client object
    this.client = client;
}

// Result handler method 
PyAMFResult.prototype.echo_Result = function( result ) {
    trace( result ); // prints "Hello World!"
}

// Fault handler method displays error message 
PyAMFResult.prototype.echo_Status = function( error ) {    
   // Notify the user of the problem
   trace( "Remoting error: " );
   for ( var d in error ) {
       trace( error[d] );
   }
}
