Getting into RED5

Hi, Happy new year to all. Hope this brings with it success, friendship, faith and hope to everybody’s life.
To start with lets start with Red5. For past some weeks I was working on Red5, yeah its just some 2 -3 weeks only. All these time I was only trying to get my first application going and running Flash remoting in it. It took me some time but its worth.

First of all to go with Red5 it is mandatory to have Flash and JAVA handy. Belive me, its the same as AS3 development in an IDE such as Eclipse. There are syntax changes but over all its the same kind of stuff. So it is fun developing in JAVA as well as in AS3. RED5 supports JAVA SPRING framework for applications out of the box. Being said that, Spring makes its easy for a beginniner developer to get going in JAVA as all one need to write is a POJO(Plain Old Java Object) and configure one XML file.Cool, so lets get started. Below are the source files, I hope it helps somebody out there.

Source Files One

Source Files Two
I am currenntly working on Red5 v0.7.0 Final as the 0.8RC1 gave me some problem in the beginning.I will try that once I am more comfortable in RED5.So my point here is as a beginner you must try a stable version of the RED5. I am on the standalone version of it.Though it is possible to run RED5 inside of TOMCAT server as well.The installation is simple and hassle free.I have installed it in (C:\Red5) folder of my Windows Vista Machine. Once installed one can go inside the root folder of RED5(C:\Red5) and start the server by running “red5.bat” file.Once the server is up and running, just point your browser to “http://localhost:5080/” and you will see the default home page of RED5 s\erver.Fine, so everything is up now.We will write a simple application, I mean java application and test it.
I am not going in detail about how to wite a JAVA class, as there are a lot of tutorials available for it.Just remember that you have to write a simple java class. In order to get the communicate with the Flash client all the JAVA classes which needed to be accessed must extend “org.red5.server.adapter.ApplicationAdapter” class.I will be writing two classes, one in a default package and two inside a package, just to know whether we can access all the classes from inside a package. The classes look as below

class : RedTest

import org.red5.server.adapter.ApplicationAdapter;

public class RedTest extends ApplicationAdapter {
public String greet(String msg){
return msg;
}
public int add(int a,int b){
return a+b;
}
public int subtract(int a,int b){
return a-b;
}

}

class : RedGreet

package com.services;
import java.util.Arrays;
import org.red5.server.adapter.ApplicationAdapter;
import com.services.Greetings;
public class RedGreet extends ApplicationAdapter {
public int add(int a,int b,int c){
return a+b+c;
}
public String sayMe(String message){
return message;
}
public Greetings greetUser(){
Greetings greet=new Greetings();
greet.userName=”saumya”;
greet.userMsg=”Red5 giving back Greetings Object.”;
return greet;
}
}

Thats all from java side. I am serious.Compile these classes and they will produce the class files out of the java files. Now all that remains is the configuration.
All the applications on RED5 remains on “webapps” folder (C:\Red5\webapps).For a quick start I will suggest just copy all the contents from the “echo” folder (C:\Red5\webapps\echo) and paste them in a new folder named “redVO”(C:\Red5\webapps\redVO).Well the the name is not important as long as you remember it to configure it in the coming XML file. So lets take the name as “redVO”. Now lets copy all the class files inside “C:\Red5\webapps\redVO\WEB-INF\classes” folder.Just make sure the packages are same as the deveopment.So the classes will be paced as “C:\Red5\webapps\redVO\WEB-INF\classes\RedTest.class” and “C:\Red5\webapps\redVO\WEB-INF\classes\com\services\RedGreet.class”.

Now all that remains is configure some xml and properties files.Come back to the folder “C:\Red5\webapps\redVO\WEB-INF”.we need to configure “red5-web.properties”,”red5-web.xml” and “web.xml” files.
I found this is the most critical task of the RED5 development as I struggle a bit with this :). Its not tough but must know where to do what.
So the first thing to do is, configure the “red5-web.properties” file.the contents of the file looks as below

webapp.contextPath=/echo
webapp.virtualHosts=*,localhost, 127.0.0.1

The thing to change here is the real name of the folder “C:\Red5\webapps\redVO”, it can be something else  but for a beginner it is best to get the name same as the folder. So our properties file will look as below

webapp.contextPath=/redVO
webapp.virtualHosts=*,localhost, 127.0.0.1

Now lets open the “web.xml” file, in this file the only thing needed to change is the thing we did in the last file.We need to add the same folder name here as well. Find an XMl node as below

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/echo</param-value>
</context-param>

and change it to “redVO” from “echo”

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/redVO</param-value>
</context-param>

Now the most important and essential setting of all, the whole expanation may take a new blogpost. I will just explain in brief. Just look at a line as below

<bean id=”web.handler” class=”org.red5.server.webapp.echo.Application” />

change it to

<bean id=”web.handler” class=”RedTest” />

If you remember we had created this “RedTest” class in the default package. In the same way add below lines

<bean id=”Test.service” class=”RedTest” />
<bean id=”Greet.service” class=”com.services.RedGreet” />

So these are refferring to the Classes we have created in JAVA.The important thing here is the “id”.Whatever we put in the “id” field will be refferred to from our Flash client. Another thing is the “service” must be a postfix to the “id” as “Test.service”.Now if we need to call a method of “RedTest” class from Flash we need to call it as “Test.myMethod();” or “Test.greet();”

Thats all :).In flash end I have this code below in

Well.The cool thing is if you look at the flash code, we are conneting to

nc.connect(“http://localhost:5080/redVO/gateway&#8221;);

This is remoting call.But if we want to call the rtmp too we can call it and this will be as

nc.connect(“rtmp://localhost:1935/redVO”);

Now just start the red5 server and test movie in Flash IDE, you will see the results. Thats it, hope you are enjoying. Happy flashing 🙂

Advertisements

Author: saumya

designer / developer / maker / educator @saumya

21 thoughts on “Getting into RED5”

  1. Hi,

    Thanks for your post !!

    Can you plz explain, if this Red 5 server is capable of streaming mp3 files ? If yes then how ? , any small application or setting etc would be a great help.

  2. hi Ranjit,
    Here is the info about RED5 at the project home page http://osflash.org/red5
    Yes, it is capable of streaming, not only audio but video too.
    There are plenty of examples available at the project home site.
    Anyway, I will try to put up one as soon as I get some time.

  3. Hi Saumya,
    I am getting following error while starting newly installed Red 5 on one of our server,

    wrapper | –> Wrapper Started as Console
    wrapper | Launching a JVM…
    jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
    jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
    jvm 1 |
    jvm 1 | WrapperSimpleApp: Unable to locate the class org.red5.server.Standalo
    ne: java.lang.UnsupportedClassVersionError: Bad version number in .class file
    jvm 1 |
    jvm 1 | WrapperSimpleApp Usage:
    jvm 1 | java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_a
    rguments]
    jvm 1 |
    jvm 1 | Where:
    jvm 1 | app_class: The fully qualified class name of the application t
    o run.
    jvm 1 | app_arguments: The arguments that would normally be passed to the
    jvm 1 | application.
    wrapper | <– Wrapper Stopped
    Press any key to continue . . .

    I have checked JAVA_HOME, CLASSPATH and PATH environment variables also and they are correctly mentioned !!

    I am getting whats the problem is? Do u know how to solve this error ?

  4. Hi Sowmya,

    We are using Drupal. In our site we are going to stream Audio and Video Live Recording. we choosed Red5 server to Record and store my data in our server.

    Can you guide me to install Red5 in my machine. We are using Windows Vista OS. Can u tell the process of installation and download links for Red5 in our Machine.

    Thanks,

    RamMohan S

  5. Hi Saumya,

    I wanted to stream a file hosted in oflaDemo application on Red5 server. For that I am using a CS3 flash player application in which I m reading a xml containing the URL of a file kept in Red 5. And the problem is , the player is not able to stream it.

    Not able to figure out the answer, Can u plz help ?

  6. hello
    i think im stuck at a point. ive just started using red5 version 0.7. (installed it correctly). now everytime i open the sample .swf files and click to open the connection. it gives me an error alert saying “please check connection uri string and try again”.
    what do u think could be the reason for it.. and also… i just checked by double clicking the batch file of red 5.. it says”system cannot find the path specified”.
    how do i tackle all this. your help will be greatly appreciated.
    thank you

  7. hi samuya,
    i have to make an application that will show the video on demand , but the user will first send the request to asterisk server then to red5 , red5 will fetch the requested video name from database and will send back directly to user, i tried to know how it will be done , still many doubts ,
    please guide in this regard.

  8. Hi Pragya,
    I am not very sure about how Asterisk works. If the server can process any serverside scripts, then its just a matter of forwarding the messsage from the user to Red5 server and on the user and listening to the event from Red5 and giving it back to the user. Else, just make a call to Asterisk server and wait till your job is done from Asterisk,then make a call to Red5.
    Hope that helps you in any way.
    Would love to know if fixed,how you implemented it. Thanks.

  9. Well friends, I am sorry for the late. But finally I got my old files. So putting the links online now. These are the working links to download the sources. Hope that helps someone.

    file one
    file two

    Happy flashing

  10. hi thank saumya, but i want to ask you
    where i can put RedVo.swf and where i can find echo folder in my server because i didnt find it in webapp. im very newbie
    thank before

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s