I am trying to implement my own version of the Terracotta with Smartfox Server based on your demo. I was able to run the demo fine, but ran into some problems when I implemented my own code. From Actionscript, I used the URLLoader as per your code to access ClusterAccess.py, but the data returned is the entire contents of ClusterAccess.py, and not the chosenServer, i.e. nodeData[0] and nodeData[1] doesn't return the ip and the port number but the lines "from javax.servlet.http... ClusterAccess(HttpServlet)" and "def __init__(self)" (basically the lines between each ":"). How can I return the correct python variable to Actionscript? I am currently coding purely on Flash Actionscript 3, without Flex.
Am still stuck, would really appreciate any help or suggestions. When I traced my Flash file, it is accessing the correct .py file, and am currently using the ClusterAccess.py file given in your demo. I have started up the Terracotta server and start-monitor does indicate the connections when I start up all the SFS instances. However I just cannot get the lobbyNode to return the chosenServer values correctly.
I am currently running the files from the bin folder of my localhost i.e. C:\wamp\www\bin. ClusterAccess.py is in the main www folder. The SFS instances are running from the Server folder of my SFS installation, with a copy of the terracotta-2.5.2 folder given in your demo on the installation path of SFS.
Here are my codes:
// when application is initiated
public function init():void {
clusterCfg = new ClusterConfiguration();
clusterCfg.addEventListener(Event.COMPLETE, onConfigReady);
clusterCfg.addEventListener(IOErrorEvent.IO_ERROR, onConfigFailure);
clusterCfg.loadConfig();
}
public function onConfigReady(evt:Event):void {
var gateway:Object = clusterCfg.getGateway()
zone = clusterCfg.zoneName
extensionName = clusterCfg.extensioName
// Call the load-balancer
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLobbyNodeReady);
loader.addEventListener(IOErrorEvent.IO_ERROR, onLobbyNodeFailure);
loader.load(new URLRequest("http://" + gateway.addr + ":" + gateway.port + "/ClusterAccess.py"));
}
public function onConfigFailure(evt:Event):void {
trace("Failed loading configuration. Reason: " + evt.toString());
}
public function onLobbyNodeReady(evt:Event):void {
lobbyNode = evt.target.data as String;
// this returns the entire contents of the ClusterAccess.py file.
}
Secondly, do I need to re-compile any .py code in order to use it through actionscript's URLLoader?
I am currently running the files from the bin folder of my localhost i.e. C:\wamp\www\bin. ClusterAccess.py is in the main www folder
I think there's a misunderstaning here... you are mentioning wamp but the ClusterAccess.py file is a Java servlet written in Python and executed through the Java Python interpreter (a.k.a Jython) in the Jetty webserver.
In simple words, you need to run that file within the SmartFox embedded webserver, if you move it in another environment it won't work
Ok got it! Thanks Lapo! Managed to work out the problem.
Just one more question about the clustering. Right now inside each of the cluster-lobby[n].xml files, I added some other rooms other than the Lobby room. However the smartfox client in actionscript returns only the Lobby as the room when I call the getRoomList() function. Why is that? I don't need the entire cluster to know when a user changes room, so I'm wondering if I can do this without going to the serverside but do as per the normal smartfox.joinRoom function in actionscript, which was working before I implemented the clustering in my program. Right now when I do smartfox.joinRoom(...), it says the room does not exist.