Fernando Florez has just shared some interesting classes for FMS on the Flash Media List. SThey are handy if you want to load balance FMS connections on the client side. Why would you do that? It's cheaper than doing it serverside and also you have more control to switch servers for new connected clients on the fly without restarts, let you work with different providers, etc.
Here's some sample code:
import funciton.models.UpstreamServer;
import funciton.utils.DateUtils;
import funciton.net.BaseConnector;
import funciton.utils.PendingCall;
var upstream1:UpstreamServer = new UpstreamServer("myhost1", "myDemoApp", 1935, "rtmp");
var upstream2:UpstreamServer = new UpstreamServer("myhost2", "myDemoApp", 443, "rtmps"); // box with security certificate upstream2.down = true; // it is down for maintenance
var upstream3:UpstreamServer = new UpstreamServer("myhostAtOutsourceCompany", "myDemoApp", 1935, "rtmp");
upstream3.max_fails = 3; // if it fails for more than 3 times disable it from the pool upstream3.expires = DateUtils.HOUR_IN_MS; // if it reaches max_fails re-enable it on the pool after an hour upstream3.backup = true; // it's a backup server. Use it only if upstream1 fails
var baseConnector:BaseConnector = new BaseConnector();
var ncHandler:PendingCall = baseConnector.connect(new Vector([upstream1, upstream2, upstream3]);
ncHandler.onResult = function(nc:NetConnection):void{
trace ("connection ok");
}
ncHandler.onFault = function():void{
trace ("connection failed");
}
BaseConnector class will do all the pool handling/logic. The first successful connection is kept and the rest are closed / discarded. With upstreams declared you can implement round robin or client hash logic easily.
The code is on github and can be found here: http://github.com/funciton/funciton-aslib
Thanks Fernando, great stuff.