Prev | Current Page 802 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

hx
import haxe.remoting.AsyncConnection;
class Client
{
public static function main()
{
var cnx = AsyncConnection.urlConnect(???http://localhost:2000/server.n???);
cnx.onError = function(e)
{
trace(???Error: ??? +Std.string(e));
}
cnx.calc.sum.call([5,4], function(data)
{
trace(data);
});
}
}
// content of server.hx
class Server
{
public static function main()
{
var server = new neko.net.RemotingServer();
server.addObject(???calc???, new Calc());
if(server.handleRequest())
return;
// handle other requests (not remoting)
neko.Lib.print(???Neko remoting server waiting for a request???);
}
}
class Calc
{
public function new() { }
public function sum(x : Int, y : Int) : Int
{
return x + y;
}
}
The RemotingServer class is described later in this chapter in the ??? Proxy Objects ??? section and in the
??? TicTacToe Game ??? section. The most important thing is that a client cannot invoke any method available
on the server but those belonging to the instances registered with the addObject() method.


Pages:
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814