Silverlight and FluorineFx integration with the FluorineFx Silverlight library
In the previous entry I was showing how to connect a Silverlight client to the Flash Media Server. This guide shows how to connect Silverlight to a FluorineFx powered ASP.NET web site.
Network Security Access Restrictions in Silverlight 2
In order to have the client able to connect you must have a policy server running and to configure FluorineFx’s RTMP server to listen in the 4502-4534 port range.
You can use the FluorineFx Silverlight Policy Server provided OR to configure the gateway to start internally the policy server. This requires the following settings in the web.config file:
<fluorinefx> <settings> … <silverlight> <policyServer enable=”true” policyFile=”~clientaccesspolicy.xml”/> </silverlight> … </settings> </fluorinefx>
The clientaccesspolicy.xml file must be located in the web site root.
Define a RTMP channel in the service configuration file with the endpoint url set as uri=”rtmp://{server.name}:4502″
The RTM application
Add the “apps” folder to the web application and create a new app.config file
<?xml version=”1.0″ encoding=”utf-8″?> <configuration> <application-handler type=”ServiceLibrary.SOTestApplication”/> </configuration>
In the service library (or in the web site project if medium trust is not enforced) define the application handler class:
using System; using FluorineFx; using FluorineFx.Messaging.Api; using FluorineFx.Messaging.Adapter; using FluorineFx.Messaging.Api.SO; using FluorineFx.Messaging.Api.Service; using FluorineFx.Messaging.Api.Stream; namespace ServiceLibrary { public class SOTestApplication : ApplicationAdapter { int _usersID; string _history; public SOTestApplication() { } public override bool AppStart(IScope application) { _usersID = 1; _history = string.Empty; this.CreateSharedObject(this.Scope, “users”, false); return base.AppStart(application); } public override bool AppConnect(IConnection connection, object[] parameters) { lock (typeof(SOTestApplication)) { connection.SetAttribute(“uniqueUserID”, _usersID); //set the shared object ISharedObject usersSO = GetSharedObject(this.Scope, “users”); ASObject aso = new ASObject(); aso.Add(“uniqueUserID”, _usersID); aso.Add(“connectStartTime”, DateTime.Now); usersSO.SetAttribute(“user” + _usersID, aso); _usersID++; // Call the client function ’setHistory,’ and pass // the initial history if( connection is IServiceCapableConnection ) (connection as IServiceCapableConnection).Invoke(“setHistory”, new object[]{_history}, null); } return base.AppConnect(connection, parameters); } public override void AppDisconnect(IConnection connection) { int uniqueUserID = (int)connection.GetAttribute(“uniqueUserID”); ISharedObject usersSO = GetSharedObject(this.Scope, “users”); if( usersSO != null ) usersSO.SetAttribute(“user” + uniqueUserID, null); base.AppDisconnect(connection); } public void msgFromClient(IConnection connection, string msg) { lock (typeof(SOTestApplication)) { int uniqueUserID = (int)connection.GetAttribute(“uniqueUserID”); msg = “user” + uniqueUserID + “: ” + msg + “\n”; _history += msg; ISharedObject usersSO = GetSharedObject(this.Scope, “users”); usersSO.SendMessage(“msgFromSrvr”, new object[]{msg}); } } } }
Create the Silverlight Application project and select the existing web site to host the client. Follow the steps described in the Creating Silverlight project section of the previous post.
Run the web application
Here is a screenshot of the running application
Get the latest FluorineFx code and binaries from the SVN repository
Update: the Silverlight library is available for download in the latest FluorineFx version
