RTMP SharedObject's for Free
RTMP, which stands for Real-Time Messaging Protocol, can be used in place of custom socket servers and HTTP to keep a bunch of clients synchronized via a single server. Each client maintains a constant connection to the RTMP server which then doles out synchronization as changes are reported by said clients. Flash 9 and ActionScript 3 have a lot of RTMP support built into the NetConnection and SharedObject classes which make it relatively simple to use ... assuming you have an RTMP server.
At the time of writing this Wikipedia still seems to stay that you need to buy commercial, closed source software such as Adobe Flash Media Server in order to facilitate RTMP clients. Well actually there are other implementations available and one of those I'm going to show you today is FluorineFx made by The Silent Group. It's free and works pretty good even at its current pre-release stage.
Unfortunately the documentation and samples are not quite up to snuff: they assume you already know about RTMP/SharedObject/NetConnection stuff, which I don't, and consequently it took me a while to figure it all out. Rather than letting you slog through the same muck, I'm going to step you through an example RTMP application where a server keeps a bunch of clients up to date, I called it SharedObjectTracer because all it really does is share a tiny bit of data between clients and trace out all the synchronization events as they happen.
Requirements for FluorineFx and the SharedObjectTracer example (things I'm not going to explain): You're competent with ASP.NET 2.x and IIS (Microsoft's Web Server) and you know how to build ActionScript 3 (*.AS) files into SWF's which you know how to run.
With that out of the way, use the following steps to get the example installed:
Once you're fairly sure it's running you can compile SharedObjectTracer.as into a SWF and start it up. The only display it has is a TextField which fills the entire stage and shows all the traces being made by this little application. By running only one instance of this example, you'll only ever see one instance being mentioned in all the traces, so I suggest you start up a couple more and just watch for a minute or two.
See what it's doing?
Each application gives itself a random number (0 - 100), prefixes that with "Object_", and then creates a timestamp property on the SharedObject using that name string. Every 7.5 seconds or so, it updates this timestamp on the SharedObject and all the connected clients receive a "change" event on that property. The client that initiated the change gets a "success" (assuming it was), or a "reject" if something went wrong; see SyncEvent for details on the synchronization event information.
Check out the comments in the ActionScript 3 code for more on how this little example works on the Flash side. It should be noted that the way it's written, it could probably work for any RTMP server, I just happen to be using the FluorineFx RTMP server in this case.
If you're wondering where the FluorineFx RTMP server is, it's in IIS now because you loaded the web page. See it is implemented as an HTTP Handler that is registered in the web.config file. When you hit the web page, it loads FluorineFx which then launches its RTMP server and sticks around as long as IIS is running and doesn't get reset. Flash is almost always embedded into pages served up by the web server, so by doing it this way your website will not only provide the client as a Flash app, but the request will start the RTMP server anytime it's needed as well!
The port I use for the example, 11935, is the standard RTMP port (1935) prefixed with an extra 1 to not get in the way of anything. On the server side, the port is configured in the .\WEB-INF\flex\services-config.xml file. On the client in ActionScript, the port is specified in the call to NetConnection's connect() method.
At the time of writing this Wikipedia still seems to stay that you need to buy commercial, closed source software such as Adobe Flash Media Server in order to facilitate RTMP clients. Well actually there are other implementations available and one of those I'm going to show you today is FluorineFx made by The Silent Group. It's free and works pretty good even at its current pre-release stage.
Unfortunately the documentation and samples are not quite up to snuff: they assume you already know about RTMP/SharedObject/NetConnection stuff, which I don't, and consequently it took me a while to figure it all out. Rather than letting you slog through the same muck, I'm going to step you through an example RTMP application where a server keeps a bunch of clients up to date, I called it SharedObjectTracer because all it really does is share a tiny bit of data between clients and trace out all the synchronization events as they happen.
Requirements for FluorineFx and the SharedObjectTracer example (things I'm not going to explain): You're competent with ASP.NET 2.x and IIS (Microsoft's Web Server) and you know how to build ActionScript 3 (*.AS) files into SWF's which you know how to run.
With that out of the way, use the following steps to get the example installed:
- Download FluorineFx and install it. This is actually somewhat difficult to find, here's 1.0.0.1. Or here's just the DLL's you'll need if that's all you want, or if the install crashes for you like it did for me.
- Download SharedObjectTracer.zip, uncompress it somewhere on your machine, and then put
FluorineFx.dll,ICSharpCode.SharpZipLib.dll, andlog4net.dllassemblies into its .\bin\ directory. - Create a new Virtual Directory in IIS on localhost called SharedObjectTracer and point it to the folder where you unzipped everything; it should contain a
default.aspxfile. If you're using IIS 6 (e.g. not on Windows XP), make sure to mark it as an application.
RTMP Server should be started now. Try telnet'ing to port 11935 on your machine to make sure it's receiving connections. You can use DebugView to view traces made by FluorineFx.Do what it says and run telnet against port 11935 just to make sure it's listening. If you're feeling even more savvy, crank open DebugView, restart IIS, and revisit the page to watch FluorineFx start up.
Once you're fairly sure it's running you can compile SharedObjectTracer.as into a SWF and start it up. The only display it has is a TextField which fills the entire stage and shows all the traces being made by this little application. By running only one instance of this example, you'll only ever see one instance being mentioned in all the traces, so I suggest you start up a couple more and just watch for a minute or two.
See what it's doing?
Each application gives itself a random number (0 - 100), prefixes that with "Object_", and then creates a timestamp property on the SharedObject using that name string. Every 7.5 seconds or so, it updates this timestamp on the SharedObject and all the connected clients receive a "change" event on that property. The client that initiated the change gets a "success" (assuming it was), or a "reject" if something went wrong; see SyncEvent for details on the synchronization event information.
Check out the comments in the ActionScript 3 code for more on how this little example works on the Flash side. It should be noted that the way it's written, it could probably work for any RTMP server, I just happen to be using the FluorineFx RTMP server in this case.
If you're wondering where the FluorineFx RTMP server is, it's in IIS now because you loaded the web page. See it is implemented as an HTTP Handler that is registered in the web.config file. When you hit the web page, it loads FluorineFx which then launches its RTMP server and sticks around as long as IIS is running and doesn't get reset. Flash is almost always embedded into pages served up by the web server, so by doing it this way your website will not only provide the client as a Flash app, but the request will start the RTMP server anytime it's needed as well!
The port I use for the example, 11935, is the standard RTMP port (1935) prefixed with an extra 1 to not get in the way of anything. On the server side, the port is configured in the .\WEB-INF\flex\services-config.xml file. On the client in ActionScript, the port is specified in the call to NetConnection's connect() method.
Labels: rtmp

1 Comments:
I've always wondered how the RTMP listener gets started. Now I know :) Thanks a lot!
Post a Comment
Links to this post:
Create a Link
<< Home