Setting up the Red5 server turned out to be a little more of a challenge than I thought it would (just a reminder, as always I’m doing this on Snow Leopard). I installed the stand alone version in my applications folder (you can download it from http://red5.org/wiki/Releases), double clicked it and didn’t see anything happen. I was at least expecting some sort of interface to let me know it was running, but nothing. With a little searching I found that opening my browser with http://localhost:5080 would show me that it was up and running. Installing a few of the demos proved it was the real deal, but now I had to figure out the man behind the curtain: how the server was running, and how to make it run my stuff.
That simply took right clicking on the Red5 application and choosing “show package contents”. Annoyingly simple for the time it took me to figure out, I’m embarrassed to say. Under Content/Resources/Java you find the folder webapps, and that’s where the magic happens. Anything you want running on the server should be here.
Before I get to making Apps run on the server, I have to make a plug for the Red5 plugin for Eclipse. It makes a huge difference during development and has been a lifesaver for me. Long story short, use this tutorial to set up the Red5 plugin on your machine: http://red5.org/wiki/Red5Plugin. It didn’t quite match up with my version of Eclipse but it was close enough to make it work. Once you have that plugin installed, you’re ready to start working on your App.
On the same Red5 wiki they walk through creating a new Red5 project http://red5.org/wiki/Red5Plugin/CreatingRed5Projects. The only problem is that there really isn’t much there. So I thought I’d fill in a few of the gaps here, and if you see any more you’d like me to fill let me know. For now I’m just putting this up as a reference for myself, since getting a working app has taken me all over the web and back.
I was interested in creating a video chat application using flash. That’s why I needed Red5 in the first place instead of other open source servers out there. Red5 allows streaming with RTMP, which is necessary for live chats and overkill for non-streaming.
My video chat would need server side Java code (it turns out I used Cirrus Flash peer 2 peer instead and didn’t even need Red5 – if you want to see take a look at http://Zazzer.me) and probably PHP, along with the client stuff. In order to set up the server so that the client could actually find it took a decent amount of searching. I’m assuming you’ve already started by creating the project, and now you’re writing the Java source. Here is an example of what needs to be in the source for it to interact with the client:
1 2 3 4 5 6 7 8 9 | package myPackageName; import org.red5.server.adapter.ApplicationAdapter; public class Application extends ApplicationAdapter { public String hello(String name) { return name + "I see you"; } } |
Here I’ve extended the ApplicationAdapter class, which is the one that listens for the client. So the big part is good to go, but the devil is in the details. What else do I have to configure in order to get this to work? Well there are a few simple files that are not configured for you (at least they weren’t for me) that you have to fix before any flash client will find this application. Those files are web.xml, red5-web.xml, and red5-web.properties.
In web.xml you must include:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <context-param> <param-name>webAppRootKey</param-name> <param-value>/yourAppName</param-value> </context-param> <servlet> <servlet-name>rtmpt</servlet-name> <servlet-class>org.red5.server.net.rtmpt.RTMPTServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>rtmpt</servlet-name> <url-pattern>/fcs/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>rtmpt</servlet-name> <url-pattern>/open/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>rtmpt</servlet-name> <url-pattern>/close/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>rtmpt</servlet-name> <url-pattern>/send/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>rtmpt</servlet-name> <url-pattern>/idle/*</url-pattern> </servlet-mapping> |
Red5 uses webAppRootKey to create the handshake with the NetConnection class in Flash. In this case rtmp://yourServerName/yourAppName would be the string you pass to NetConnection in order make the connection.
Web.xml is done, next up: red5-web.xml. This one was tricky because every resource I came across just told me to include a bean specifying the web.handler. However it didn’t work until I had everything else you’ll find here. It may work with less for you, but like I said this is more a reference for me anyway so I’m putting it all up:
I didn’t really bother to check to see why it didn’t work before but did after the extra beans. If you’re interested you tell me! Last of all red5-web.properties is simple enough:
webapp.contextPath=/yourAppName
webapp.virtualHosts=*, localhost, localhost:8088, 127.0.0.1:8088
That should do it for the server. Once that’s rollin it’s just a matter of writing the client and connecting with the rtmp I mentioned before. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | package { import flash.net.NetConnection; import flash.display.Sprite; import flash.text.TextField; import flash.events.NetStatusEvent; public class FMS3Connect extends Sprite { private var nc:NetConnection; private var rtmpNow:String; private var msg:String; private var connectText:TextField; private var posX:Number; var responder:Responder = new Responder(setValue, null); function setValue(obj:Object):void { trace(obj.toString()); } function Connect () { nc=new NetConnection(); nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect); rtmpNow="rtmp://yourServerName/yourAppName"; nc.connect (rtmpNow); } private function checkConnect (event:NetStatusEvent):void { trace(event.info.code); switch(event.info.code) { case "NetConnection.Connect.Success": nc.call("hello",responder,"billy"); trace("success"); break; default: trace("no luck amigo"); } } } |
Ok so I won’t swear by that code because I just wrote it now, but if it doesn’t work it’s damn close because it’s almost the same as what I have in my app and that works.
I think this is quite enough for one post. Hopefully it’s helpful to any hapless readers, let me know if I should fix anything (assuming anyone makes it to this line).
Also if you’re looking for more information to fill in the gaps, I’ll start posting links to resources I find below:
http://www.red5tutorials.net/index.php/Tutorials:Getting_Started_With_Red5_Server