Prerequisites:
• Intermediate AS3 knowledge
• Flex 3
• Flash Media Server and/or Red5 + Java EE
Resources:
• View Flex source
• View Flash Media Server Source
• View Red5 source
• Download Flex source
• Download Flash Media Server Source
• Download Red5 source
• An indispensable guide to migrating from FMS to Red5 by Joachim Bauch
Includes:
• A Flex Project that can connect to either the Red5 or FMS back end, depending which app/server you are running on localhost.
• A simple FMS SharedObject demo .asc file.
• The equivalent Red5 SharedObject demo Java Project.
Tips:
Getting errors in your Java project? Try right clicking on the Java project and going to “Properties/Java Build Path”. Remove any references to unbound libraries and click “Add External JARs…”, then navigate to red5.jar in the root of your Red5 installation.
Can’t select to “Debug As/Debug on Server” in your Java project? Right click on your Java project and go to “Properties/Project Facets”. Make sure to select “Dynamic Web Module” and “Java”, then apply the changes.
The purpose of this example is to compare on a basic level the experience of developing for Red5 and FMS.
The application allows users to send messages to all users who have the application open in real time.
The great thing about the way Red5 is implemented is that from the Flex client’s perspective you are dealing with it in exactly the same way you would deal with FMS, so if you need to port a bunch of your existing FMS code over to Red5, you may well not need to change your Flex client code at all.
All the FMS and Red5 versions of the back end are doing in this example is the following:
• on receiving a client connection they create a non persistent server side SharedObject named “message” as a means of broadcasting messages to clients.
• next they define a “sendMessage” function for the Flex client to call when the “Send” button is pressed. This function accepts a message string, which is then passed back to all connected clients via the “message” SharedObject calling the “receiveMessage” function defined in the Flex client code.
Differences in implementation:
In FMS the application entry point is implicitly created for you and is available as an object named “application”. As an AS3 developer coming to this it feels like stepping back in time to the fuzzy old days of AS1, pre strict typing, pre code hinting, pre clear, bug free and manageable code.
In Red5 you get to explicitly declare your application entry point class in a strictly typed language. The fact that you get to declare the application, to see its dependencies and inheritance chain and have the benefit of auto code completion is very reassuring. The fact that you now have a wealth of Java libraries at your disposal is pretty cool too.
In FMS you have to declare functions that can be called by clients on the client object that is received by the server side code when a user connects. I always found this a bit odd and it confused me for a while.
In Red5 you can declare functions to be called by clients as methods of the application itself, or no doubt as methods of classes that are referenced by the application. Again this just feels more ‘proper’ to me in that I’m exposing a public API for the application itself, rather than defining a list of functions that are available to a client on the server’s representation of the client object as it connects.
Differences in user experience:
When developing a Flex app in FMS I found myself at a loss what to do with the server side code I was creating. Ideally I wanted this to be a Flex Library, an ActionScript Project or something similar so that I could code my entire application from the same IDE. The problem with that approach is that you’re trying to push a square peg into a round hole, as the notion of building the project is lost with .asc files. Instead I ended up just creating a simple folder structure for the .asc files and editing them in Flash to take advantage of the code highlighting.
Developing with Red5 however is light years ahead, especially with the introduction of the Red5 Eclipse Plug-in that can actually automatically create your server and client side code for you..! Red5 server side code is a Java project, so can be edited in a Java Perspective within Eclipse. This allows you to switch between the Flex and Java Perspectives within the Eclipse IDE when editing your client and server side code. You can also actually build your Java project and even run it within Eclipse by publishing a local instance of the server.
It seems slightly counter intuitive to me that its the free product here that’s obviously streets ahead of the quite pricey product. I’m not complaining though! Plus the free product is the one that is much more flexible in terms of where it can be installed as its built on Java rather than .Net. Ideal!







