Prev | Current Page 811 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

This is enough to activate
the haXe magic. The created proxy class acts in the client code and is checked by the compiler as if it was
an instance of ServerClassToInvoke .
Part II: Server Side, JavaScript, and Flash: Oh My!
438
In the following code, the explored Calc example can be changed to take advantage of the proxy API.
This time the connection is synchronous from JavaScript to a remote Neko HTTP server. Only the client
code is reported.
import haxe.remoting.Connection;
class CalcProxy extends haxe.remoting.Proxy < Calc > {}
class Client
{
public static function main()
{
var cnx = Connection.urlConnect(???http://localhost:2000/server.n???);
var calc = new CalcProxy(cnx.Calc);
trace(calc.sum(5,4));
}
}
The CalcProxy class is defined in just one line of code. Every Proxy instance must be created passing
to the constructor the correct path to the remote object that must be associated to the proxy. A proxy
instance behaves exactly as the mirrored class.
The methods of an AsyncProxy act in a similar way but accept an optional extra argument that
is the function that is delegated to handle the result when this becomes available.


Pages:
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823