Basic SharedObject example in Flex, Red5 & Flash Media Server

December 4, 2008 by robsilverton

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! :-)

Getting started with Red5 and the Eclipse Plug-in on PC

December 3, 2008 by robsilverton

It can be difficult to know where to start with Red5 if like me you have a reasonable level of experience with Flash/Flex/Flash Media Server, but zero experience with Java.

I had a bit of a hard time trying to find relevant tutorials that worked for me as a PC user, and consequently had a lot of difficulty getting to my first Hello World Red5 app.

The following post then details what I’d wished I’d known when I started:

 

Resources:

The definitive resource for everything Red5 (as defined by the Red5 team) is http://wiki.red5.org/

 

Installing the Red5 Server:

Download the Tarball of Red5 Server 0.8 Release Candidate 1 from here.

The reason for downloading the Tarball version rather than the Windows Installer version is that the latter has been known to have issues and may not work for you.

Un-tar (extract) the Red5 files and folders. The root folder will be called “dist”. Rename it “Red5″ and move it to “C:\Program Files\”.

Within the Red5 folder there is a file named “Red5.bat”. Double clicking this file will start the Red5 server running in a DOS Prompt window. Closing this window will stop the server running.

While the server is running, go to http://localhost:5080/. If you can see the Red5 page you know your server is running. Have a click around and play with the various demos.

 

Installing the Eclipse IDE for Java Developers:

Download and install the Eclipse IDE for Java EE Developers. You can find it here. You will need this to create and deploy your Red5 apps.

 

Installing the FlexBuilder Eclipse Plug-in:

If you haven’t done so already you may want to switch over to the Eclipse Plug-in version of FlexBuilder for the most seamless development experience when creating Red5 apps. You can find that here.

 

Installing the Red5 Eclipse Plug-in:

Download the plug-in from here and follow the installation instructions. If you’re using the Ganymede version of Eclipse or the installation instructions are confusing for any other reason, the “Installing Red5 Eclipse Plug-in” section of this post may help you. Make sure to download the version that targets v0.8 of the server.

 

Creating your first Red5 Project:

I recommend watching this video for instructions on how to create your first Red5 project, though you may want to skip the first 5 mins as its basically an introduction bringing you to the stage you should have already reached by this point, and I wouldn’t worry about changing the default code in the first instance, just see if you can get it running “as is” to begin with. Again I found that the experience using Ganymede is slightly different to the experience outlined in the video, so the “Creating a Red5 Web Project in Eclipse” section of this post should help you to fill in the blanks.

 

Deploying your first Red5 Project locally:

If you skip 26 minutes into the example video you’ll see how to setup and run your server. Make sure to set your Runtime Directory for the server to “C:\Program Files\Red5″. The same goes for the next paths in the setup, see the “Running your server-side app in Eclipse” section of this post for details.

The main problem that you will more than likely run into is that you can’t get the server to actually run within Eclipse. This doesn’t really matter though as you can still run the server from the “Red5.bat” file as explained above. The important thing is that in creating this instance of the Red5 server within Eclipse you’ve created a means of easily deploying your app to your Red5 installation. The first stage in attempting to run the server should have successfully copied your app over to “C:\Program Files\Red5\webapps\”, which is a pretty neat feature.

In future if you want to redeploy your app, while in the Java EE Perspective in Eclipse go to “Window/Show View/Servers”, where you should see your instance of the Red5 server. Right click on the server and select “Clean…”, this should redeploy your app(s) to the server installation for you.

 

Running your first Red5 Project locally:

Now that your Red5 app is deployed, run the Red5 server by double clicking the “Red5.bat” file as explained above. When testing changes to your app after redeploying it, always remember to stop and restart the Red5 server by closing and reopening the Red5 DOS Prompt window.

 

Testing your Red5 app:

Now that the server is up and running with your app successfully deployed, your next step is to try and connect to it from your Flex client. Go back to your auto generated Flex project within the Flex Development perspective in Eclipse, right click on the Flex project root and select “Debug As/Flex Application”. This should open your Flex app in a browser window and (all being well) successfully connect to your Red5 app.

 

So hopefully by now you’ve created your first Hello World app in Red5. It wasn’t entirely straightforward and it didn’t work 100% as you’d expect, but overall it was pretty damn good for a Beta, and the development experience was light years ahead of Flash Media Server.

Please leave me a comment if you’ve read this and it helped you, I’d be happy to hear if you get up and running quickly. :-)

Red5 v0.8, Red5 Plugin v0.2. IT WORKS!!!! :D :D :D

December 2, 2008 by robsilverton

I’m very pleased to report I’ve just had my first positive experience developing with Red5! :D

It seems like a lot of my problems could have been caused by the fact that the Red5 Plugin simply doesn’t work with version 0.7 of the server.

I’ve been advised by the main man himself to download and install version 0.8 RC1 of Red5 and try again, but unfortunately I initially tried to install this version and it failed. So instead I was advised to downloaded the Tarball version, un-tar it, create a Red5 directory in Program Files and copy the contents over. I assume that because I haven’t gone through the install procedure it makes sense that Red5 doesn’t show up in Add/Remove Programs or in Services anymore.

So the next step was to try and recreate the server within Eclipse and publish it. On doing so I was confronted with this QuickTime related error:

Starting Red5 (org.red5.server.Shutdown)

java.lang.NoClassDefFoundError: Files\Java\jre1/6/0_07\lib\ext\QTJava/zip

Caused by: java.lang.ClassNotFoundException: Files\Java\jre1.6.0_07\lib\ext\QTJava.zip

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Exception in thread "main"

I was actually quite pleased to see this error as I hadn’t seen it before and felt like I might be making progress. After a quick Google I found this thread on the Red5 mailing list by a user with a similar problem. As with the JAVA_HOME issue, this was again to do with Environment Variables. I checked my CLASSPATH var as instructed in the response to the thread (right-click My Computer/Properties/Advanced/Environment Variables), and bizarrely it was set to:

.;C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip

The first thing I noticed was that for some reason this string starts with the characters “.;”, which really didn’t look right, so I deleted those characters, logged off and back on to reset my environment vars and tried again. No joy. Next I tried adding quotation marks to the string as suggested and the error went away.

BUT… then I was confronted with another error…

Starting Red5 (org.red5.server.Shutdown)

Attempting to connect to RMI port: 9999

java.io.IOException: Failed to retrieve RMIServer stub:

...

So I Googled the first few lines of the error again, only to be confronted with 5 results, two of which were my own blog. So it appears I’m back to the point I’d reached before when I gave up on publishing the server from Eclipse or creating the application code automatically with the plugin, and started playing with simple examples that had been published on a mac. As you can imagine I was quite disappointed by this point. :-(

Wondering what to do next, I thought I’d just try running the server by double clicking the red5.bat in Program Files/Red5. This opened a DOS prompt and started the server successfully as you would expect. I then thought I’d just try connecting my previous Mac published example to the server to see if it works. It worked. Ok… so the next problem I was having was the weird caching behaviour. So I stopped the server by closing the DOS prompt, changed a little bit of the Java code in the tutorial, published the files by cleaning the server within Eclipse (as mentioned before this is a good way to auto deploy to the server even if you can’t get the server running in eclipse), restarted the server from the red5.bat file and ran the Flex client code within Eclipse. The changes had taken effect..! I tried it 3 or 4 more times just to make sure and it continued to work! :-)

My next question then was if that’s started to work.. maybe the server and client side code generated by the Red5 Eclipse Plugin would now work too..? So I created a new Red5 project with auto generated code, and went through the same deployment method as above. IT WORKED..! :D

Still skeptical, I tried changing and republishing the code several times just to see if the changes would take effect. IT STILL WORKED!!! I NOW HAVE A WORKING HELLO WORLD EXAMPLE!!!

Its been a bit of a battle, but I’m now elated to report I’ve reached the point where I can actually start writing Red5 applications! I also have to say that I feel fairly smug about the fact that the problems I was having weren’t down to simple errors of my own making (unless you consider my not knowing that v0.2 of the plug-in targets Red5 server v0.8 an error of my own making, but I don’t remember seeing any mention of that via the path I took to the plugin). I notice the new home of the plugin does clearly offer two versions though for 0.8 or 0.7 or below, which is cool.

The plugin still doesn’t work exactly as it’s supposed to (i.e. I can’t actually publish the server), so if anyone has any suggestions on how to get it fully functional I’d be very happy to hear them. In the meantime though I can now start creating my own Red5 apps! :D

Big thanks to the lovely guys at Red5 for their continued support which has brought me to this point. Although I’ve never had such a battle getting something working, I’ve also never had such generous offers of support from such senior members of a team. By way of recompense my next post will be a condensed guide for Java novice PC users hoping to setup Red5 to steer them through all of the pitfalls I fell into. After that I’ll start recreating my simple FMS examples with Red5 equivalent code. Can’t wait! :D

Red5: finding it impossible to develop for on PC.

November 27, 2008 by robsilverton

After deciding that the Red5 Eclipse Plug-in was the source of most of my Red5 related woes, I’ve just spent a whole day trying to deploy a Red5 app without it.

Because the project code generated by the Plug-in doesn’t work when deployed on my PC, I’ve had to adapt the source of a simple example that was written on a Mac.

However if I deploy that app by hand (i.e. copying and pasting the folder containing the META-INF & WEB-INF folders into my Red5 webapps directory and renaming it Red5Tut) it doesn’t work, even after stopping and restarting the Red5 service several times.

But… if I deploy the app automatically from within Eclipse by cleaning the Red5 Server instance I created (as mentioned before I can’t actually run the server from within Eclipse, so cleaning it is as far as I go) then start the Red5 process externally in Services, the app actually works!

Once the app is up and running though, the next problem is trying to update it. Even if I manually stop the Red5 service, delete the app folder from webapps, clean the server in Eclipse (automatically redeploying the app to webapps on the server), it still exhibits same behaviour as if its just cached the last version somewhere. How could this be? Is Eclipse caching the project somehow? I tried rebuilding/resaving it multiple times…

Short of buying a Mac I’m pretty stumped as to how I’m actually supposed to develop using this software. I’m starting to think that FMS is well worth the license fee and that the comparatively toy town server side language is a small price to pay when you consider we managed to get the system up, running and tested in a matter of hours… I’ve had more problems with this software than any other I can recall, which is a shame as all I initially wanted it for was a free version of something I already knew how to use. I know its all in Beta, but I wasn’t prepared for the level of testing I’ve obviously signed up for.

Question 1: Why does it make a difference if I deploy the app using the Eclipse Plug-in instead of doing it manually?

Question 2: Does anyone know how to fix or at least get around this weird caching problem I’m having when trying to update app?

If anyone has any answers or ideas I’d be really grateful. I’m gearing up to work on a multi player game project and at the moment (as much as I’d like to be able to) it looks like I can’t use Red5.

Red5 Eclipse Plug-in v0.2 PC User Feedback: Hello World! (of Pain)

November 25, 2008 by robsilverton

Thanks to a nice fellow named Jérôme I’ve finally got a Hello World example app running from Eclipse, though not the server itself, and not one of my own making. My attention was directed to this helpful post in which a video describes the basic process for setting up a Red5 project using the Eclipse plug-in. As you’ll have noticed from the video this chap was using a Mac so quite probably didn’t run into the world of pain that currently seems to befall PC users of the plug-in.

As suggested I downloaded his source files and imported them into Eclipse. I then attempted to run the server from within Eclipse, which failed, but it did successfully copy the server side Java code to the Red5 installation’s “webapps” folder for testing.

Also as suggested I started the Red5 server externally from Eclipse in the Services manager (for me that’s in “Start/Settings/Control Panel/Administrative Tools/Services”), then debugged the client code in Eclipse, and it worked!!!

So the Red5 server isn’t working within Eclipse, but at least I know my projects can connect to the server if its not running in Eclipse. The next question then is why didn’t my automatically generated demo code work when I went through the equivalent process (demonstrated in the video tutorial) on a PC? I added a simple “for in” trace to the onConnectionNetStatus() function in my auto generated code and traced out this result when testing with the Red5 server running outside of Eclipse: 

NetStatusEvent objectEncoding = 3
NetStatusEvent description = No scope "Demo" on this server.
NetStatusEvent code = NetConnection.Connect.InvalidApp
NetStatusEvent application = null
NetStatusEvent level = error
NetStatusEvent code = NetConnection.Connect.Closed
NetStatusEvent level = status

It seems for some reason if you (or at least if I) create the code on a PC it fails to deploy properly on the server. I went through the project creation process again just to make sure, but no cigar.

Summary of findings:

• Red5 Server v0.7 seems to work fine as a standalone service on a PC
• It seems that Red5 Server v0.7 can’t currently be successfully published in the Red5 Eclipse Plug-in v0.2 on a PC
• It seems that the auto generated Java code is successfully deployed to the server by the Red5 Eclipse Plug-in v0.2 on a PC, but…
• Once deployed the auto generated app isn’t recognised by the server when debugging the client code, so maybe the app code is screwy?

I’d be very interested to hear if anyone has had a similar or wildly different experience on a PC. It sounds like there are at least a few of us hitting exactly the same problems.

Conclusions:

From what I’ve heard and seen it sounds like the Red5 Eclipse Plug-in works great on a Mac and no doubt is the useful tool it intends to be (please correct me if I’m wrong). On a PC however (for me at least) it has actually been more of an obstacle to using Red5, as had I found the code that I’m now using for my first working app before, deployed it manually and run Red5 from the Services manager, I’d no doubt have had a much more positive experience all round.

I hope these findings are of some use to the community and the team at Red5. Although I’ve had a bunch of problems its still early days for the server and the plug-in, and I’m still in awe of the level of effort and expertise going into both projects. Hats off to the team, hope this is some good tester feedback. ;-)

Red5 Eclipse plug-in: The next issue after the JAVA_HOME issue…

November 19, 2008 by robsilverton

You’ll see in this previous post that I ran into a fair few issues trying to get the Red5 Eclipse plug-in working, as have a several others it seems including fellow FlashBrightonian and Flash expert Iestyn Lloyd. Due to time constraints I unfortunately had to admit defeat with only an inkling of a problem with the JAVA_HOME environment variable.

Then I received a very helpful comment from a nice man named Paul Tondeur informing me I should point my JAVA_HOME variable at the root folder of my Java installation rather than the java.exe file I’d targeted. After a machine restart I attempted to restart the Red5 server within Eclipse, and was happy to see that this problem had been overcome. Although… I was pretty unhappy to then be met with the following error:

FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
Press any key to continue . . .

After a bit of Googling I came across this thread on the Red5 mailing list. The suggestion most relevant to my problem seemed to be that port 8787 might already be in use causing the launch of the server to fail, and I should check what’s using that port with the TCPView tool from Microsoft. As it turns out that port was being used by the java.exe process.

Following Dominick Accattato’s advice on this thread I opened up Windows Task Manager and ended the java.exe process, then restarted the server from within Eclipse. I then saw this message…

Listening for transport dt_socket at address: 8787

…and nothing else until the process timed out 120 seconds later, when this appears:

Attempting to connect to RMI port: 9999
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.1.31; nested exception is:
    java.net.ConnectException: Connection refused: connect]
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:323)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
    at org.red5.server.Shutdown.main(Shutdown.java:70)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.1.31; nested exception is:
    java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1871)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1841)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
    ... 2 more
Caused by: java.rmi.ConnectException: Connection refused to host: 192.168.1.31; nested exception is:
    java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
    ... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:519)
    at java.net.Socket.connect(Socket.java:469)
    at java.net.Socket.<init>(Socket.java:366)
    at java.net.Socket.<init>(Socket.java:180)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
    ... 12 more

Has anyone else experienced this and found a solution? I notice a chap by the name G is already one step ahead of me judging by his last comment. Any luck G?

I had my doubts about using an Open Source project rather than a commercial product like Flash Media Server as I had a feeling it could lead to a world of pain, and unfortunately so far this has more or less been my experience. I think maybe I should’ve taken my own advice and held off until the version 1 release, as undoubtedly there will be issues with a Beta release and you may need a bit of specialist knowledge to steer you through the hazards. Hopefully my posting this will save a few others a few hours here and there in the meantime.

As always, all credit to the Red5 team for making something that is all set to be amazing at the version 1 launch, I just wish I could start playing with it before that point… ;-)

Red5 IDE Eclipse Plug-in v0.2

October 14, 2008 by robsilverton

So today I spotted that v0.2 of the Red5 IDE Eclipse Plug-in was released 10 days ago. D’oh.

http://www.newviewnetworks.com/nvnhome/blog/client/?p=95

Does anyone know of a site that provides the de-facto information and downloads for red5? I get confused looking between:

here: http://code.google.com/p/red5/

…and here… http://osflash.org/red5/

…and here… http://red5.org/ (which doesn’t actually have a homepage but does contain content)

…and here… http://red5world.com/

…plus of course the various blogs of the contributors.

Would be great if one site was established a the main place to start and the other sites linked to it, though I’m sure this is probably one point on a massive To Do list somewhere.

How to upgrade from v0.1 to v0.2:

http://jira.red5.org/confluence/display/tools/Tutorials#Tutorials-HowdoIupgradefromRed5Plugin1.0to2.0%3F

How to install v0.2:

http://jira.red5.org/confluence/display/tools/Installation

See my previous post about differences to the installation procedure when using Eclipse 3.4 (aka Ganymede).

I’ve tried running the Red5 server from Eclipse again and I got the same error “the system cannot find the path specified“.

I’ve also tried running/restarting the Red5 server from the Services window, but when I run the client Flex app it fails to connect.

I just want it to work now please. :-(

Getting up and (nearly) running with the Red5 Eclipse Plug-in v0.1

October 13, 2008 by robsilverton

The Red5 plug-in for Eclipse has recently been brought to my attention by none other than Chris Allen from the Red5 team (!), so after my recent near miss with getting a simple Red5 app up and running, this got me excited enough again to have another crack at it.

Unfortunately though after another reasonable effort today I’ve again fallen short of actually getting a “Hello World” app to run. :-(

It seems to me that Red5 and the Red5 Eclipse Plug-in will be amazingly useful and productive tools down the line, but they’re just not quite there yet. Plus the current quality of information surrounding the project seems quite disparate, so finding the most useful or most up-to-date information can be a bind.

FMS still definitely has a few key points over Red5:

  • Its easy to setup FMS and get an app running, whereas doing the same in Red5 is still beyond my (perhaps somewhat limited) powers.
  • FMS has clear branding on the product and (for me at least) gains a certain amount of perceived reliability by its association with Adobe. Even though Red5 is set (in my view) to be a far superior product, I think without the vision of a talented brand/product manager it could be in serious danger of being overlooked by large swathes of the Flash community who just don’t realise how good it is/how easy to use it will be.

In the meantime I hope Java newbies (like myself) don’t get too disheartened with it due to its current problems, as once the team hit that monumental version 1.0 milestone its all set to be something truly awesome.

Installing Red5 Eclipse Plug-in

Go to the download tab of this Flex app and if using Eclipse 3.3, follow the instructions. If however (like me) you’ve recently downloaded Eclipse 3.4, do this instead:

Go to “Help/Software Updates…”

Click on “Add Site” on the right to bring up this dialogue:

red5_eclipse_add_site

Copy and paste this url: http://www.red5.org/projects/red5plugin/update_0.1.x/ into the text field and press OK.

This url should now appear in your available software list as below. Make sure its selected.

red5_eclipse_select_project 

Now click “Install…” at the top right. This will bring up a slightly odd Install dialogue with nothing in it, but continue unperturbed.

red5_eclipse_install

Installation will take a few minutes and should prompt you to restart Eclipse on completion (which you should do).

So that wasn’t quite what we were expecting from the online instructions, but it wasn’t too difficult to figure out and Eclipse has been updated recently so fair enough.

Creating a Red5 Web Project in Eclipse

The next thing you should do is watch this tutorial on creating a Red5 Dynamic Web Project by Dominick Accattato.

If you’re using a Mac and Eclipse 3.3 this tutorial is probably fine for you, but if you’re on a PC and using Eclipse 3.4 like me, you’ll need to be aware of the following:

There will be another step in Eclipse 3.4 in the project creation process regarding targeting the Red5 runtime. You will need to press “Next” and browse to your install of Red5 (so for me its: C:/Program Files/Red5) and click “Finish”.

red5_eclipse_target_runtime

The next difference between Eclipse 3.3 and 3.4 is instead of clicking “Next” as per the tutorial to go to the Project Facets, you need to select the “Modify” button next to Configuration on the same screen:

red5_eclipse_conf_mod

Selecting the “Red5 Application Generation” option is much the same when you get there though. You should be able to click finish at this point and watch in wonder as it creates your server side Java app and client side Flex app. No more wondering what files to include then.. how cool is that..!?! :-)

Running your server side app in Eclipse

When the example video goes to “Run As/Run On Server”, if you’re in Eclipse 3.4 you’ll need to click “Next” rather than “Finish” and you’ll be presented with this screen:

red5_eclipse_runOnServer 

Like before you’ll have to browse to your Red5 installation, and if you’re on a PC you’ll need to select “red5.bat” rather than “red5.sh” and “red5-shutdown.bat” rather than “red5-shutdown.sh”.

So I’m feeling pretty pleased with myself that I’ve made it this far, but then when I finally go to run the app I’m confronted with “Server port In Use 5080-Http”:

red5_eclipse_problem 

After some discussion and head scratching we decided to look in “Start/Settings/Control Panel/Administrative Tools/Services” where we find Red5 is already running. So I told it to stop by clicking the link below:

services_stop_red5

Then tried again, and got this problem…

red5_eclipse_noPath

So then we look at the “red5.bat” startup script in “C:\Program Files\Red5″ and begin to wonder if the JAVA_HOME variable isn’t specified…

red5_bat

Then we right click on My Computer, select “Properties/Advanced/Environment Variables” and scroll through the list to find JAVA_HOME isn’t specified…

java_home

…so we set it to the path of the JDK I downloaded in the previous tutorial, press OK, restart the machine (just to be sure) and try again.

Still no cigar.

Then, just as I’m about to give up I spot this at the bottom of my Java EE perspective in Eclipse:

red5_eclipse_clean

So I clean my server and run it again, but it still doesn’t work… :’(

Hopefully this’ll help prevent others from having to figure this all out for themselves, but I’m afraid after a day at this I’m going to have to admit defeat and actually get on with some work. The really annoying thing is that it would be so cool if I could only get it to work..!

I’m going for a lie down in a darkened room now, but if you have any ideas please let me know. ;)

Red5 vs FMS (and getting to grips with Java)

October 10, 2008 by robsilverton

Background

I thought I’d take advantage of the Red5 session at this year’s Flash on the Beach to check out what exactly Red5 is and whether I should bite the Java bullet and switch over from Flash Media Server. Unfortunately I couldn’t make it to the session, but a trusted colleague went in my stead and came back enthused by the merits of Red5. (here’s a link to a video of a similar session, and here’s a link to the FOTB session pdf)

I was informed that programming in Java would be very similar to programming in AS3, and would provide a development platform that’s streets ahead of the Server-Side ActionScript (aka JavaScript 1.5) that FMS supports. I was also told that the install process is dead straight forward (I have my doubts about Open-Source projects), so I thought maybe I’m missing a trick here, and decided to install Red5 and have a play.

 

Installing Red5

First I downloaded and installed Red5 v0.8.0 Release Candidate 1. For whatever reason this didn’t work for me, so not a good start. After some head scratching and discussion I decided to try Red5 v0.7.0 Final instead. This version installed perfectly with very minimal bother, so I guess the lesson here is if you’re a beginner never install a Release Candidate 1 version! Once you’ve got Red5 up and running, you should be able to go here: http://localhost:5080/ to view the Red5 test page and example apps.

 

Installing Eclipse and the Java IDE

After enthusiastically playing with the demo apps provided for a bit, the next step was to download and install Eclipse so I could get up and running with Java.

Once I had the Eclipse framework the next step was to install a Java IDE on top of it. I opted for the “Eclipse IDE for Java EE Developers” because it seemed to be the most feature rich version of the IDE, and downloaded it from here.

 

Getting to grips with Java

The next problem was getting used to Java, a language I’ve never even looked at before. To do this, I strongly recommend looking in “Help/Help Contents” in Eclipse, then going to “Java Development User Guide/Getting Started/Basic Tutorial”. This is a really well written tutorial and gave me a great grounding in developing Java. If you get a bit stumped by the first hurdle in this tutorial regarding not being able to find the JDK (that you probably haven’t downloaded yet), go get it here. I went for JDK 6 Update 7 as the newer version was a Release Candidate Beta, and I’d already learned my lesson regarding RCs. :-)

After going through that tutorial I was very pleased to see that the Java IDE I’d downloaded was just like my current favourite development tool: FlexBuilder, but way better! (why the hell didn’t Adobe implement Content Assist in FlexBuilder?!?) I was also pleased to have confirmation that Java is ridiculously similar to AS3, and looked forward to building my server-side apps in code way more similiar to AS3 than FMS’s AS1 equivalent.

 

Eclipse, Java and FlexBuilder

As my next move was going to be trying to build a simple Flash app that runs on Red5, I decided it would be handy to switch over from my standalone installation of FlexBuilder to the Eclipse plug-in version. You can download the plug-in version here, but you’ll need to sign in to the adobe site first.

Once I had this version of FlexBuilder installed I could quickly switch between Java and Flex Development perspectives within Eclipse and manage the whole application development process from within on IDE (which I think is very cool). When developing with FMS I’d got into the habit of editing my server-side code in Flash to take advantage of the code highlighting it provides for asc files, and my client side code in FlexBuilder, which wasn’t so cool. Also, because the server-side code is written in a dynamic language you can forget about any niceties like code hinting. :-(

 

Hello World, Hello Red5

So by now I was all setup to build my first Hello World red5 application. The next step then was to find a suitable tutorial on the web, and after trying out a few not so good tutorials I found one named Getting started with Red5 server. This tutorial would’ve been perfect had the application worked after going through all the code and all the permutations of the code in the trailing comments by other perplexed developers with a fine tooth comb. The comment that really threw me though was the one posted 10 months after the tutorial advising “You need to make a jar file from you java project and store it in the lib directory of your application”. It seems something pretty fundamental must’ve changed with Red5 over those 10 months if it was now necessary to include a jar file of your project… I checked through the other example apps in my installation of Red5 and they all did indeed contain a lib folder with a jar file of the application, plus 3 other jars: “logback-classic-0.9.8.jar”, “logback-core-0.9.8.jar” and “slf4j-api-1.4.3.jar”.

 

Conclusions

After having a bit of a play with FMS and Red5, I think its safe to say that the future of multi user Flash apps lays firmly in the lap of Red5, unless Adobe suddenly regain interest in developing FMS, which seems to now be on a back burner. The overall development experience provided by Red5 is (or at least will be) streets ahead of FMS. Plus not only can Red5 provide the same functionality as FMS, its a “fully fledged j2EE server” which allows you to build the rest of your application logic in Java and take advantage of the extensive code libraries available.

But… that said, I’m cautious to invest too much time developing reusable systems in Red5 at the moment as its not even out of Beta yet and may well still be subject to major structural revisions. If you view the Red5 roadmap you’ll see they’re currently at the version 0.8 release and (I’m hoping) not too far off the version 1.0 Public Release. Plus in version 0.9 they intend to provide more extensive documentation and to even support server-side AS3(!), so after this point I may need to reconsider whether I should be coding server-side in Java or AS3…

In short, Red5 is an awesome (and free!) tool, but I think I’m going to bide my time and continue to fiddle around with FMS until the full version 1.0 release. This should allow me to brush up on my client side multi user app code without investing too much energy on the server-side development. Plus FMS is after all just another technology that I can sell my services in, regardless of how comparatively poor the server-side language is.

Simple Chat 3: User based chat in FMS & Flex

August 13, 2008 by robsilverton

Prerequisites:

• Intermediate/Advanced AS3 knowledge
• Flex 3
• Flash Media Server

Resources:

View source files
Download source files

This tutorial builds on the previous Simple Chat tutorials and concepts from the Adobe FMS Server-Side component architecture.

The main addition to the code has been the introduction of users.asc, which is responsible for handling all user related data and events (in much the same way as chat.asc handles all message related data/events). The user is now automatically assigned a username on connecting to the application, and other users are notified of their arrival and departure in a users list. Users have the option to change their username, and their username now appears above their messages in the message text area.

Hopefully by this point a lot of the code and concepts in this version are quite familiar from the previous tutorials, so I’m thinking if you just download this one and have a play with it, the new additions and their function should be fairly self explanatory.

I’ve added (what are hopefully) fairly lightweight comments to the code to hint at the purpose and the types of the more important functions, and have stripped it down to the bare necessities, so I reckon if you’ve done ok with the first two then you’ll probably get your head around this one in no time. :-)

If you have any questions about this one though please feel free to leave me a comment and I’ll consider expanding this post to cover the topic.

Actually, here’s one bit of code that I do think’s worth mentioning. Notice how the sendMessage function in our example simply stores and passes a reference to the user object and the message string:

Chat.prototype.sendMessage = function( user, mesg )
{
    this.history.push( {user: user, mesg: mesg } );
    while ( this.history.length > this.histlen )
        this.history.shift();
    this.message_so.send( “onSendMessage”, user, mesg );
}

…this allows the Server-Side code to store the necessary data without making any assumptions about how your view wishes to present it. Presentation is instead handled by Flex in applicationComplete.as like this:

public function onSendMessage(user:Object, mesg:String):void
{
    messagesTf.text += user.username+” says:\n”+mesg+”\n\n”;
    messagesTf.validateNow();
    messagesTf.verticalScrollPosition    = messagesTf.maxVerticalScrollPosition;
}

If you want to add text formatting or extra wording to your messages, you should do so in the view code like this and keep your data clean, not like the Adobe component example below where they add all sorts of formatting to their message/client data on the Server-Side:

FCChat.prototype.sendMessage = function( client, mesg ) {

    var cglobal = this.getClientGlobalStorage(client);

    mesg = this.hiliteURLs(mesg);

    var hexColor = “#”+cglobal.usercolor.substring(2, cglobal.usercolor.length)

    mesg = “<font color=\”" + hexColor + “\”><b>” + cglobal.username + “: </b>” + mesg + “</font><br>\n”;
    this.history.push( mesg );
    while ( this.history.length > this.histlen )
        this.history.shift();

    this.message_so.send( “message”, mesg );
}

How nasty is that..?! ;-)