Usage of js.XmlSocket(…)
I wasn’t sure how to compile and supply the flash-based socket wrapper. See compile.hxml and JSClient for help on how to do this.
ExternalConnection is not initialized in Flash
This one stumped me for a while, and it turns out I was trying to connect the js/flash bridge before the flash socket was available. My solution to this was to add a delay to the js socket connection code. A better solution (if possible) would be to detect when the flash object loads and then try the socket connection, or to just catch the exception and repeatedly try to connect.
XML Policy file
Not being a flash programmer myself, I didn’t realise that flash requires a “policy file” which lets it know if it can open a socket connection to a server. But after some googling, I came across a haxe implementation of a policy file server (included in this example.) The policy file itself is cross-domain.xml and is fairly self-explanatory. The policy file server should listen on port 863.
Running “neko server.n” will run both the primary server and the policy file server.
Browsing the haxe ThreadRemotingServer API, I saw a reference to “policy file”, I assume this means that the HaXe crew have built in the policy file functionality into ThreadRemotingServer, but I was unable to get it to work.
The code can also be browsed online at: http://hg.bp.io/public/misc/HaxeJSRemoting/
For haxe and socket programming try using Node.js with the haxe type signatures here
Thanks for the link.
When I originally came to haxe, I struggled with the js/flash bridge, and so ended up writing a simple Node/JS chat app using your Node.js signatures alongside socket.io. It all worked great and the next step was to adapt the Haxe remoting proxies to work, but after examining the remoting source I realised that there was some crazy voodoo magic in there, and so went back to Neko/JS.
It would be awesome to be able to target Node.js (with something analogous to ThreadRemotingServer) that is haxe remoting compatible, and also to be able to haxe a remoting compatible socket.io wrapper. I would do these things, but I really just want to get on with the game experiments I’m building. :)