Prev | Current Page 824 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

main() method a new socket is created and associated to a SocketConnection .
A new instance of the class is also created and stored in a static variable client . The client is also
registered in the _global space of the Flash environment to be reachable when a message is received
from the server.
The socket connects to a localhost address on port 2001 but any domain and port can be used as long as
it is not used by another process.
The class has a very simple logic all dedicated to invoke the remote methods and to draw the user
interface.
import haxe.remoting.SocketProtocol;
class GameApi extends haxe.remoting.AsyncProxy < IPlayerServer > {}
class GameClient implements IGameClient
{
public static var client : GameClient;
public static function main()
{
var socket = new haxe.remoting.Socket();
socket.onConnect = onConnect;
var cnx = haxe.remoting.SocketConnection.socketConnect(socket);
client = new GameClient(new GameApi(cnx.PlayerServer));
flash.Lib._global.client = client;
socket.connect(???localhost???, 2001);
}
public static function onConnect(connected)
{
if(!connected)
client.


Pages:
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836