Thursday, January 10, 2008

Flash Media Server 2 basic concepts

The new Flash Media Server 2 (FMS) does no longer include or install any sample files. I think this is a good decision as it caused a lot of confusion with people being under the impression that the swf files needed to be on the same server as FMS itself. This is not the case, let me try and explain.

Flash Media Server 2 doesn't really have much in common with a web server, instead it enables your swf to make use of live or streaming media and data access functionalities. Your swf is still being served as usual via a web server and sometimes, especially in a development environment, the webserver may reside on the same machine as FMS. In most cases however the FMS machine is a separate, physical machine to your webserver.

I like to compare it to a database server: MySQL or MSSQL can run but does not have to run on the same machine as your webserver. The database server can be located half way around the world yet your database connection will still be established reliably.
This is very similar to how FMS operates - your swf will make a connection to FMS 'behind the scenes' after it has been served to the user's browser via your web server. The swf doesn't care where it was being served from - as long as the rtmp connection string points to the right place it will attempt a connection to FMS and if the connection succeeds then your application can use FMS functionalities. Macromedia has a graphic that shows this setup (see right) , I hope they don't mind me using it.

Let's look at how an rtmp address is contructed. Usually the rtmp address takes this format:
rtmp://fcserver.domain.com/app[/appinstance]
but sometimes it can also look like this
rtmp:/app[/appinstance]

app in this case specifies your application (a folder underneath FMS's applications directory) and appinstance is an optional application instance name. If you omit the application instance then FMS will automatically create and connect you to the default instance called _definst_. In the end you are therefore always connecting to an instance of your application even if you do not explicitly do so. This concept is important to understand as it directly affects the storage locations of flv files and it's something that many new users find problematic. Once you know how applications and instances are set up though it will make perfect sense.

The second rtmp string rtmp:/app[/appinstance]only shows one forward slash and no server or vhost address, this means the rtmp address is local - it will only connect successfully if the swf file has been served from the same machine as the one where FMS resides. I try and avoid this syntax whenever possible and usually only use it for local testing as it can lead to problems in a production environment when you move your FMS installation to another machine: You would either have to update the rtmp string, recompile and redeploy your video or you needed to make sure that your web server moves along with FMS. This seems cumberstone to me.

Instead I prefer the first syntax rtmp://fcserver.domain.com/app[/appinstance]
This fully qualified rtmp string is more readable and gives a lot more information about where the FMS machine is located, in this case at fcserver.domain.com
A swf using this syntax will attempt a connection to fcserver.domain.com/app no matter what happens, it could be run locally as well as served from a web server.

No comments: