Tuesday, March 13, 2007

How to create a sample application using Red5 and Flash

How to create a sample application using Red5 and Flash

Step 1:-

Get a default application template from doc folder of your Red5 installation directory (e.g. for windows: - “C:\Program files\Red5\doc\templates\myapp”).
Copy this folder into Red5\webapps\ directory.

Step2:-

Now we have a default template available for running the server side application. We will change the default configuration accordingly. Rename myapp folder to sample. This sample folder will be the name of your application. We will now change the configuration files inside sample folder. The structure of the application will be like this-




Open the red5-web.properties file and change the contextPath to sample like below –

webapp.contextPath=/sample
webapp.virtualHosts=localhost, 127.0.0.1

Open web.xml file and change the display and webAppRootKey like below–

</DISPLAY-NAME>My First sample application with Red5</DISPLAY-NAME>

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

Now open the red5-web.xml file and change the application name likes below-

<bean id="web.handler"
class="org.xyz.Application"
singleton="true" />

where org.xyz is the package structure used here. It could be replaced with actual application structure.
lib directory will contain the jar file of our application. We will explore it later while creating an application.

Step3:-

We are ready with the server side application configuration. Now we will create the actual application which will interact with the flash client.

Open any java IDE like eclipse and create a new java project. Name it to Sample. Create following structure in the Sample project.





src folder will contain the application package structure org.xyz. Compiled class file will be under classes folder and lib folder will contain the jar of compiled class.

Now create a build.xml file for building this project with ant tool. The sample build file will be like this-
<project name="My Sample Red5 Project" default="compile" basedir=".">

<target name="clean" description="Clean output directories">

</target>

<target name="compile" depends="clean">
<javac destdir="./classes" source="1.5">

</javac>
</target>

<target name = "jar" depends ="compile">
<echo message ="Getting class files from classes directory"/>
<jar destfile="./lib/app.jar" basedir="./classes"/>
<echo message ="jar creation done"/>
<copy file ="./lib/app.jar" tofile ="C:\Program Files\Red5\webapps\sample\WEB-INF\lib\app.jar"/>
<echo message="jar copied to red5"/>
</target>
</project>

Here in “jar” target we have copied the created jar file inside our application directory under webapps folder of Red5 installation. One can manually do the copy paste.

Note: - Don’t forget to add red5.jar from your Red5 installation in the CLASSPATH of eclipse so that it can find the Red5 libraries and compile the application without any errors..

Step4:-

Now we will create our source file. Create a java file, name it to Application.java

The sample application file will be like –

Application.java

package org.xyz;

//log4j classes
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

//Red5 classes
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;

/**This is the sample application class */

public class Application extends ApplicationAdapter{
/**Variable used for generating the log*/
private static final Log log = LogFactory.getLog(Application.class);

/**This method will execute when Red5 server will start*/
public boolean appStart(IScope app){
if(super.appStart(app) == false){
return false;
}
log.info("Application start method of Application called");
return true;
}

/**This method will execute when first client will connect to Red5 server*/
public boolean roomStart(IScope room){
if(super.roomStart(room) == false){
return false;
}
log.info("Inside room start of Application");
return true;
}

/**This method will execute everytime when a client will connect to Red5 server*/
public boolean roomConnect(IConnection conn, Object params[]){
if(super.roomConnect(conn, params) == false){
return false;
}
log.info("Inside room connect method of Application");
return true;
}

/**This method will be called when a client disconnect from the room*/
public void roomDisconnect(IConnection conn){
super.roomDisconnect(conn);
log.info("Inside room disconnect method of Application");
}

/**This method will be called when a client will be disconnected from application*/
public void appDisconnect(IConnection conn){
log.info("Inside app disconnect method of Application");
}

/**This method will be called from the client. This method will show “Hello World!” on *the flash client side .
*/
public String sayHello(Object[] params){
log.info(“I got your name:-”+params[0].toString());
return “Hello World!” + params[0].toString();
}


} ////////End of Application class

The above file was just to give a feel of how a server side code looks like.
Read Red5 documentation for more details on methods in AplicationAdapter class. Here we have defined a method named sayHello, which will get user name from flash client and will append this user name to “Hello World!” and will send back to flash client.

Now run the jar task of your build.xml file, this will compile your application class, will generate the desired jar and will copy it to your application directory inside Red5.

Step5:-

Now we are ready with server side application, we will start with the flash application to connect with the Red5 server.

Create a new flash document –


Drag an Alert component from window—components in the library. Open the Action-Frame and write the following lines of code-

import mx.controls.Alert;


var nc:NetConnection = new NetConnection();

nc.val = this;
nc.onStatus = function(info){
switch(info.code){

case "NetConnection.Connect.Success":
Alert.show("Got connected with application);
this.val.callServer();
break;

case "NetConnection.Connect.Failed":
Alert.show(info.application);
break;

case "NetConnection.Connect.Rejected":
Alert.show(info.application);
break;

case "NetConnection.Connect.Closed":
Alert.show("Client Disconnected");
break;
}
};
nc.connect("rtmp://localhost/sample");

function callServer(){
var resultObj:Object = new Object();
nc.call("sayHello", resultObj,"Your Name");
resultObj.onResult = function(str){
Alert.show(str); //This will display "Hello World! Your Name"
}
};
}

Now save the application and name it to sample.fla(user preferred)
The above code is Action script 1 code; you can put this code in external .As file and refer it in the application. Since this is not in the scope of this tutorial, so we will follow the above code.

Finish:-

Run your flash client and if its get successfully connect with Red5 server, it will display an alert box saying “Hello World! Your Name”

With the help of above tutorial, you can extend your application to any level.

For more information on Red5 related documents follow the link provided below-

Red5- Open source flash server
Red5-How to create new applications – Joachim Baunch
Migration Guide from FCS/FMS to Red5
Red5-How to create new application

92 comments:

javanoob said...

Hello,

Being a complete noob to java / flash / red5 any ideas what i can do to fix this error from the red5 log

INFO | jvm 1 | 2007/03/29 22:37:17 | [ERROR] 9714 WrapperSimpleAppMain:( org.springframework.web.context.ContextLoader.error ) Context initialization failed
INFO | jvm 1 | 2007/03/29 22:37:17 | org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.xyz.Application] for bean with name 'web.handler' defined in ServletContext resource [/WEB-INF/red5-web.xml]; nested exception is java.lang.ClassNotFoundException: org.xyz.Application
INFO | jvm 1 | 2007/03/29

Thanks for the tutorial.. hopefully i will get it working with a bit of a hand

Sunil Kumar Gupta said...

Hi javanoob,

This error comes when the Red5 server unable to find the class defined as a bean in red5-web.xml.

Make sure you have the jar containg org.xyz.Application class in the lib folder of your application.

javanoob said...

Any chance you can post the files used in this example? :)

Many thanks
Javanoob

Sunil Kumar Gupta said...

Hi Javanoob,

I can't becuse I am using it for a commercial product. If any problem , you can discuss here.

javanoob said...

ok, need to go back a few steps, I saw the jar being copied and assumed the build completed successfully... wrong assumption ;)

The problems I am getting I think are due to importing the classes.... been digging around window->properties->java->build path->user libraries trying to get it working but I keep getting
quite a few errors such as

ApplicationAdapter cannot be resolved to type

but I think they are due to:

The import org.apache cannot be resolved
The import org.red5 cannot be resolved

Any chance you could post on how to add the necessary classes for your example

Many thanks

Sunil Kumar Gupta said...

Hi javanoob,

The problem at your end is that , the Eclipse is not able to find the required library. See when you are creating an application using Red5 api, You need to have red5 jar in your CLASSPATH. Get all the jars from /red5/lib and add in the eclipse.

It will solve your problem,And sorry for not posting this thing in my tutorial.

Benry said...

I'm sorry, but could you be more specific as to what you mean by "Get all the jars from /red5/lib and add in the eclipse." Where do I add it? Do I create a user library and all all of these Jar files? If I do it that way, when I try to compile, it fails with the same error javanoob had.

Thanks.

Sunil Kumar Gupta said...

Hi Benry,

To compile Red5 application within Eclipse, you have to have Red5.jar in the CLASSPATH. You can take the Red5.jar from your Red5 installation and you can put it into the CLASSPATH of your application. I guess you are familiar with adding the external jars in the CLASSPATH of your project in Eclipse.

perman said...

hi man!! thanks for your tutorial!!

I got a little problem and thought you might help me.

I almost finished your tutorial, but when I built the build.xml in my sample app, and tried to compiled it with ant, I get this error:

"C:\workspace\Sample\build.xml:9: srcdir attribute must be set!"

I let you see the line code:

javac destdir="./classes" source="1.5"/

What is wrong???
thanks a lot!!!

Sunil Kumar Gupta said...

Hi Perman,

Thanks for following this tutorial. The problem is of missing source.
I will suggest you to take a look of your Eclipse settings for source directory.

Right click on project, Go to properties, under source tab, it will be written "Source folder on build path:". There you should have entry like "My Sample Red5 Project/src".

Or if it does not work, then declare a property like this-

<property name="src.dir" value="./src/"/>

and in javac task, modify it to

<javac srcdir="${src}" destdir="./classes" source="1.5"/>

and then compile again.

Hope that solves your problem.

Sunil Kumar Gupta said...

correct this line to-

<javac srcdir="${src.dir}" destdir="./classes" source="1.5"/>

Vamsi said...

HELLO WHEN RUNNING THE RED5 I GOT THIS AND WRAPPER STOPPED PLEASE TELL ME WHAT TO DO:


INFO | jvm 1 | 2008/06/04 15:56:41 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2008/06/04 15:56:41 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
INFO | jvm 1 | 2008/06/04 15:56:41 |
INFO | jvm 1 | 2008/06/04 15:56:41 | WrapperSimpleApp: Unable to locate the class org.red5.server.Standalone: java.lang.UnsupportedClassVersionError: Bad version number in .class file
INFO | jvm 1 | 2008/06/04 15:56:41 |
INFO | jvm 1 | 2008/06/04 15:56:41 | WrapperSimpleApp Usage:
INFO | jvm 1 | 2008/06/04 15:56:41 | java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_arguments]
INFO | jvm 1 | 2008/06/04 15:56:41 |
INFO | jvm 1 | 2008/06/04 15:56:41 | Where:
INFO | jvm 1 | 2008/06/04 15:56:41 | app_class: The fully qualified class name of the application to run.
INFO | jvm 1 | 2008/06/04 15:56:41 | app_arguments: The arguments that would normally be passed to the
INFO | jvm 1 | 2008/06/04 15:56:41 | application.
STATUS | wrapper | 2008/06/04 15:56:43 | <-- Wrapper Stopped

Sunil Kumar Gupta said...

Hi Vamsi,

The problem that you are getting is because of version mismatch. Bad version error comes when you run the class file compiled in higher version.

What i will suggest you to take a look of your java version and required java version in Red5.

For Ex:- If Red5 need Java 1.5 and you currently have Java 1.4

this kind of settings will give you this error.

Thanks,
Sunil

Vamsi said...

Hi tnx for the reply
I installed the red5 7 latest vesrion and i'm try to do my client side application in FlexBuilder
but i'm getting this error at run time


NetConnection.Connect.InvalidApp
hihi
NetConnection.Connect.Closed

i've created in the server side according to the Tutorial and this is my client side code:

import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.events.NetStatusEvent;
import flash.display.Sprite;
private var nc:NetConnection;
private var rsp:Responder=new Responder(rstHandler);
public function conn():void
{

nc = new NetConnection( );
nc.objectEncoding = ObjectEncoding.AMF0;

nc.connect( "rtmp://localhost/sample" );
nc.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
nc.addEventListener(IOErrorEvent.IO_ERROR,iohandl);
ta.text="connecting\n";
}
private function iohandl(event:IOErrorEvent):void{
ta.text+=event.toString()+"\n";
}
private function netStatus ( event:NetStatusEvent ):void
{

//ta.text= event.info.code+"\n";

if ( event.info.code == "NetConnection.Connect.Success" )
{

nc.call("sayHello",rsp,"HelloWorldClient");
ta.text+="calling say hello......" + " space" + event.info.code + "\n";


}
else
{
ta.text+="hihi\n"
ta.text+= event.info.code+"\n";
}


}
private function rstHandler(res:Object):void{
ta.text+=res.toString();
}

Sunil Kumar Gupta said...

Hi Vamsi,

From client side code, it's hard to say what's the actual problem.

Can you paste your web.xml in your application WEB-INF folder where you defined <context-param>
<param-name>webAppRootKey</param-name>


Also red5-web.properties and red5-web.xml where you defined the bean.

After looking into your configuration, it will be easy to tell where the problem is.

Thanks,
Sunil

Vamsi said...

webxml:webapprootkey=/sample

red5xml:web.handler:org.xyz.Application

red5prop:
webapp.contextPath=/sample
webapp.virtualHosts=*, localhost, localhost:8088, 127.0.0.1:8088

Sunil Kumar Gupta said...

Hi Vamsi,

Configuration seems fine.

Did you make and put the application jar file in lib directory of your application?

You must be getting some error messages in your log file.

Vamsi said...

hi i 've a jar file copied to lib directory of webinf
i didnt use the logs in the server side but this was the exception i found from the error log of red5:

2008-06-08 19:14:31,952 [WrapperSimpleAppMain] ERROR org.mortbay.log - Error starting handlers
java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator
at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:73)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:152)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:51)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:540)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.red5.server.jetty.JettyLoader.init(JettyLoader.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1242)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:141)
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:382)
at org.red5.server.Standalone.main(Standalone.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.PropertyConfigurator
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Sunil Kumar Gupta said...

Hi Vamsi, The tutorial was based on previous Red5 version. In new version there is a change in logging framework in Red5 and your error log also says that-

ERROR org.mortbay.log - Error starting handlers
java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator

Please follow the below links to confirm your settings related to logging once.

http://jira.red5.org/confluence/display/docs/Logging+Setup

http://jira.red5.org/confluence/display/docs/Log4j+Setup

These will sure solve your problem.

Vamsi said...

Thanks for the help sunil
it is working fine.

Vamsi said...

hi every one
i made a sample application in red 5 now i'm want to make an application which on client request stream the flv video from red5 server.
please suggest me what to do

Sunil Kumar Gupta said...

Hi Vamsi,

You can start with existing samples provided with Red5 installation. I would suggest you to take a look of OflaDemo and see how it works.

Stream a flv from Red5 is very simple, all you need to do is to put your flv files under streams directory of your application and then make a flash/flex client. Sample flash applications source you can find with red5 installation under swf directory.

Thanks,
Sunil

Vamsi said...

hi sunil i tried ou the oflademo app:
i'm only getting the metadata of the video but the video is not shown pla help me out.
below is my client side code for playing :

public function playItem ():void
{
var video:Video = new Video();
videoUIC.addChild(video);
netStream = new NetStream(nc);

netStream.client = this;
netStream.play( "DarkKnight.flv" );
video.attachNetStream(netStream);


}

public function onMetaData ( message:Object ):void
{
for ( var a:* in message )
ta.text+= a + " : " + message[a];

}

Vamsi said...

hi sunil
i connected to oflademo
and my stream is playing fine
but in the serverside code of oflademo i culdn't understand the following code properly :

IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] =
1024 * 1024;
bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] =
128 * 1024;
streamConn.setBandwidthConfigure(bwConfig);


can u please tell me wat to do

thanks ,
vamsi

Sunil Kumar Gupta said...

Hi Vamsi,

Good to know that your application is working now. The code which you shared here is used for bandwidth configuration. I would suggest you to go through this page once. It will clear all your doubts.

http://jira.red5.org/confluence/display/streaming/Bandwidth+Control+Framework

Thanks,
Sunil

Sunil Kumar Gupta said...

Blogger mistake, The URL above was not complete. Please note this

Bandwidth Control Framework

Vamsi said...

hi sunil
i got the application running perfectly fine
thanks for ur help.

Vamsi said...

Hi Sunil
can u give me an idea on how to read the flv file from red5 and pass the objects read to the serverstream that client invoked.

Sunil Kumar Gupta said...

Hi Vamsi,

Actually I am not clear to what exactly you are asking. Can you explain your problem once again?

To stream flv from Red5, you need to put flv files under the streams directory of your Red5 application. You can see the existing oflaDemo application comes with Red5.
In the client side you just have to make connection and using NetStream API to play that .flv

Hope that helps

Vamsi said...

hi sunil,
wat i want to do is to stream a large flv. For that purpose i wud like to read the a portion of that flv file individually and stream the video and then continue to remaining part of flv file in same fashion.

Moiaz said...

Hi sunil..
wherever i search for flex and Red5, I get ur post or ur blog...so u r the right person to solve my queries...
m very new to this field...need your help plz...
i want to make a webconferencing app when i googled i came to know that flex + red5 combo is one of the best...
i m used to netbeans IDE...is there anyway by which i can integrate netbeans and Red5 as javanoob did with eclipse and Red5

Sunil Kumar Gupta said...

Hi Moiaz,

Thanks for your comment. I dont think you should have any problem setting an application setup in NetBeans. You can follow this tutorial with NetBeans in place of Eclipse. Both IDE are pretty much the same.

If you are getting into some specific problem, then you can share here. But i dont think there should be any problem with basic application setup in NetBeans.

Thanks,
Sunil

Ranjit said...

Hi,
This is Ranjit.I am developing RTMP client in C++ and using Wowza as Server.
I am done upto CreateMessage and getting the response also from server.
After that I am sending Play Message and not getting any response from server.Server is only pinging the client.I have hardcoded the caller source for testing.

Problem I am facing are:
1) I don't know how to generate caller source????
2) After Play message what are 11 byte extra data which client is sending???

Give below is the data taken from wireshark.......

CreateStream message from Clien.........
0000 00 02 e3 38 9a 8c 00 19 30 14 91 c1 08 00 45 00 ...8.... 0.....E.
0010 00 4d 1e 3e 40 00 7f 06 0c 13 6b 6c 59 12 6b 6c .M.>@... ..klY.kl
0020 a1 6f 08 d5 07 8f e1 73 31 40 3d 03 f7 b7 50 18 .o.....s 1@=...P.
0030 fe 59 a3 a1 00 00 03 00 f5 05 00 00 19 14 00 00 .Y...... ........
0040 00 00 02 00 0c 63 72 65 61 74 65 53 74 72 65 61 .....cre ateStrea
0050 6d 00 40 00 00 00 00 00 00 00 05 m.@..... ...

Reply From Server.......
0000 00 00 0c 07 ac 01 00 02 e3 38 9a 8c 08 00 45 00 ........ .8....E.
0010 00 51 22 d5 40 00 80 06 06 78 6b 6c a1 6f 6b 6c .Q".@... .xkl.okl
0020 59 12 07 8f 08 d5 3d 03 f7 b7 e1 73 31 65 50 18 Y.....=. ...s1eP.
0030 5d 8b 8d 7f 00 00 03 00 00 00 00 00 1d 14 00 00 ]....... ........
0040 00 00 02 00 07 5f 72 65 73 75 6c 74 00 40 00 00 ....._re sult.@..
0050 00 00 00 00 00 05 00 40 de fe 40 00 00 00 00 .......@ ..@....

Play Message from Client....
0000 00 02 e3 38 9a 8c 00 19 30 14 91 c1 08 00 45 00 ...8.... 0.....E.
0010 00 5d 1e 46 40 00 7f 06 0b fb 6b 6c 59 12 6b 6c .].F@... ..klY.kl
0020 a1 6f 08 d5 07 8f e1 73 31 65 3d 03 f7 e0 50 18 .o.....s 1e=...P.
0030 fe 30 d7 8a 00 00 08 00 20 70 00 00 1e 14 7f 59 .0...... p.....Y
0040 00 00 02 00 04 70 6c 61 79 00 00 00 00 00 00 00 .....pla y.......
0050 00 00 05 02 00 0a 45 78 74 72 65 6d 69 73 74 73 ......Ex tremists
0060 c2 00 03 00 00 59 7f 00 00 0b b8 .....Y.. ...


Please advice me what to do?????
Where am I worng????????


Thanks in Advance....
Ranjit

Sunil Kumar Gupta said...

Hi Ranjit, I am not sure what's happening. May be i am not the right person to answer your question. I have not worked on it. It will be better if you post this problem to Red5 forum. Red5 developers can help you in this regard.

Sorry for not any help from my side.

Krishna.tur said...

Hi,
I'm new one to red5 server.I have installed red5 server on windows system.But i'm not able to run the sample applications.When i'm trying to run any application like chat i'm getting net connection failed error.Please advise me how to correct it.Thanks in advance

Sunil Kumar Gupta said...

Hi Krishna,

There may be many reasons of getting NetConnection failed message.

If you are accessing Red5 server remotely from other machine, then you need to make changes in conf/red5.properties file.

rtmp.host_port = 127.0.0.1:1935

here you need to supply the IP of the machine where Red5 server is running. For Ex.

rtmp.host_port = 192.168.2.35:1935

If it does not work, then you may need to look into your firewall.

Hope that solves your problem.

Regards,
Sunil

krishna tur said...

Hi Sunil,
Thanks a lot.Your solution to my problem is working fine.Thank you very much once again.
Hari Krishna.

krishna.tur said...

Hi sunil,
This tutorial helps me to solve problems in many situations in case of red5.Now i have one problem with chat application.That is Chat application is working fine in the system where red5 server is running means i can chat with two browsers or two tabs in red5 server installed system.
Please find my configuration file.

# HTTP
http.host = 0.0.0.0
http.port = 5080
# RTMP
rtmp.host = 0.0.0.0
rtmp.port = 1935
rtmp.event_threads_core=16
rtmp.event_threads_max=32
# event threads queue: -1 unbounded, 0 direct (no queue), n bounded queue
rtmp.event_threads_queue=-1
rtmp.event_threads_keepalive=60
rtmp.send_buffer_size=271360
rtmp.receive_buffer_size=65536
rtmp.ping_interval=5000
rtmp.max_inactivity=60000
# RTMPT
rtmpt.host = 192.x.x.x
rtmpt.port = 8088
rtmpt.ping_interval=5000
rtmp.host_port = 127.0.0.1:1935
rtmp.host_port = 192.x.x.x:1935
rtmpt.max_inactivity=60000
# Debug proxy (needs to be activated in red5-core.xml)
proxy.source_host=192.x.x.x
proxy.source_port=1936
proxy.destination_host=192.x.x.x
proxy.destination_port=192.x.x.x:1935

192 is my local machine.
When i deploy into oc4j server the chat application is not able to chat.
When i see the log file there is a message showing "address already in use:bind".Please advise me, how can i correct it.
Thanks in advance.
Hari Krishna.

Sunil Kumar Gupta said...

Hi Krishna,

I would suggest you to check your port used by Red5. From your error message, i can only think that the port, Red5 is trying to connect is not free.

krishna.tur said...

Hi Sunil,
Thans for reply me.I have seen my log file, but i'm not able to find whether it is free or not. If any chance means red5 port is not free then how can i modify it.In which file i need change the port.Please help me.

krishna.tur said...

Hi Sunil,
there is log messages when i'm chatting from other machine.But Chat is not working.Please help me.
Hari Krishna

Sunil Kumar Gupta said...

Hi Krishna,

You can change the port settings in the file "conf/red5.properties".
Then in your application, you need to connect with that port only.

I would suggest you to check if the port is not free, then you can stop other service running on that port and then start red5.

You can check this page also, it will help you to understand your problem.

http://jira.red5.org/browse/APPSERVER-124

krishna.tur said...

Hi sunil,
Thanks for reply. Actually my problem is the machine ip with the red5 port is not able to access from another machine means my red5 server ip address is 192.*.*.152:5080.this address is not access from another machine.Please help me how can i connect from another machine.
Thank you very much once again.
Regards,
Hari Krishna

Sunil Kumar Gupta said...

Hi Krishna,

If Red5 is not accessible from other machine, then make sure that port is open in your firewall.

krishna.tur said...

Hi Sunil,
Thanks a lot.Your idea is working fine for me.Your idea is simlpy superb.This is only firewall problem.Thank you very much once again.
Best regards,
Hari Krishna

krishna.tur said...

Hi Sunil,
First of all I thankful to you for all previous suggestions.
I have installed red5 server on linux machine.When i try to run the port tester swf file all rtmp ports are failed.Could you please help me how can i solve this problem.
Thank you very much once again
Regards,
Hari Krishna

Sunil Kumar Gupta said...

Hi Krishna,

I am not sure about this problem.

SandeepK said...

Hi Sunil,

A weird situation here. When I try connecting to nc.connect("rtmp://192.168.0.201/SOSample/sample"), it works but as I create my own application named "myapp", it shows "closing RTMPMinaConnection from XXXXX due to long handshake". The files exist on server at the right place, the all the paths and other stuff is triple checked as well based on your instructions above but still no luck. Any solution to this?

P.S. Examples/demos are working fine, I can access them from other computers, access them with rtmp in flash "SOSample/sample" and it says connect and just the self created applications are not working.

Sunil Kumar Gupta said...

Hi, I am not sure about the problem but you can look into this article talking about the same problem

Red5: Error connecting to a scope

Girish Kumar said...

Hi,

Is it possible to buffer video stream on client side player, when it is being streamed by Red5 Media Server, like YouTube does... If yes, how can we do it...

Thanks In Advance,
Girish

zain said...

How to make the sever side java project with NetBean?

venice said...

hi..i've tried ur sample..but when i run the sample.fla..it always returned "client closed" which is caused by NetConnection.Connect.Closed..i goto browser with this url "http://localhost:5080/" it's working..so what's wrong with tat?

jheel said...

hello
i m still getting error

srcdir attribut must be set

i have read all the comments but i m not able to solve it
please suggest me some other solution

and ya i am using NetBeans for java application

Sunil Kumar Gupta said...

Hi Jheel,

You can read about srcdir from here-

http://ant.apache.org/manual/CoreTasks/javac.html#srcdirnote

Hope it will solve your problem.

Sunil Kumar Gupta said...

Blogger mistake, Please correct the link-

http://ant.apache.org/manual/CoreTasks/javac.html#srcdirnote

jheel said...

hii
can u please suggest where should i write the following line?

<
property name="src.dir" value="./src/"/>

this is what u have sugggested once . but i m not able to understand where do i write it

Sunil Kumar Gupta said...

Hi Jheel,

Do like this-

<project name="My Sample Red5 Project" default="compile" basedir=".">

<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="classes"/>


<target name="clean" description="Clean output directories">

</target>

<target name="compile" depends="clean">
<javac srcdir="${src}"
destdir="${build}" source="1.5">

</javac>
</target>


Hope that solves your problem.

jheel said...

hii thanks its working
that error has gone
but

u have wrriten
"Now run the jar task of your build.xml file, this will compile your application class, will generate the desired jar and will copy it to your application directory inside Red5."

so i m runnig my project Sample
but i m getting more errors now

like this-
D:\Seminar\Sample\src\org\xyz\Application.java:27: cannot find symbol
symbol : class Log
location: class org.xyz.Application
private static final Log log = LogFactory.getLog(Application.class);


symbol : class IConnection
location: class org.xyz.Application
public void appDisconnect(IConnection conn)
D:\Seminar\Sample\src\org\xyz\Application.java:27: cannot find symbol

Sunil Kumar Gupta said...

Hi Jheel,

Good to hear that you solved that problem. Now the log problem you are facing is because you dont have commons-logging.jar in your classpath.

We have used Log class here in this application. So while developeing the application, you should have commons-logging jar in your classpath. You can get this jar from Red5/lib directory.

Hope that solves your problem.

Regards,
Sunil

jheel said...

i didnt have that jar file in red5/lib folder so i had download it from net and then i have incuded it in my application in lib folder

but i m still getting the same error

so what i need to do now plz suggest..

Sunil Kumar Gupta said...

Hi Jheel,

This jar should be there in lib directory where Red5 is installed.

for ex. in Windows. It can be found at-

C:\Program Files\Red5\lib

If you are using latest version of Red5, then you need log4j jar rather than commons-logging which can be found at the same place. Just include this jar into the classpath of your project and it should work fine after.

Regards,
Sunil

jheel said...

hii
i have included both the jar in lib folder of my project ...but still i m getting error.

can u give me your application ??

Sunil Kumar Gupta said...

Hi Jheel, Make sure these jars are included in your classpath. You can include them in classpath from Eclipse.

When you run ant task. You need to include these jar in the classpath. Check here how to do that.

Regards,
Sunil

jheel said...

i m not able to do this in Netbeans

i didnt find where to set class path.
can u help me how to do this in netbeans?

Sunil Kumar Gupta said...

Hi Jheel,

I have not much experience working with Netbeans. But this link can help you setting classpath

Regards,
Sunil

jheel said...

hii i have used eclipse now
and create this app
i have solved secdir error by setting the property
but now when i run the build.xml file using 2 ant build
i m getting following message
Buildfile: D:\Jinal\Seminar\Latest\Sample\build.xml
clean:
compile:
[javac] Compiling 1 source file to D:\Jinal\Seminar\Latest\Sample\classes

BUILD FAILED
D:\Jinal\Seminar\Latest\Sample\build.xml:15: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.6.0_03"

Total time: 281 milliseconds

please sugest what to do?

Sunil Kumar Gupta said...

Hi Jheel,

JAVA_HOME should point to your Java development kit. See how to set it-

Set Java_HOME

Regards,
Sunil

jheel said...

hi sunil
i have set java_home variable as per the instruction
now i m getting this error

Buildfile: D:\Jinal\Seminar\Latest\Sample\build.xml
clean:
compile:
[javac] Compiling 1 source file to D:\Jinal\Seminar\Latest\Sample\classes
[javac] javac: invalid source release: 1.5
[javac] Usage: javac <
options> <
source files>
[javac] where possible options include:
[javac] -g Generate all debugging info
javac -g:none Generate no debugging info
javac -g:{lines,vars,source} Generate only some debugging info
javac - nowarn Generate no warnings
javac -verbose Output messages about what the compiler is doing
javac -deprecation Output source locations where deprecated APIs are used
javac -classpath <
path> Specify where to find user class files
[javac] -sourcepath <
path> Specify where to find input source files
[javac] -bootclasspath <
path> Override location of bootstrap class files
[javac] -extdirs <
dirs> Override location of installed extensions
[javac] -d <
directory> Specify where to place generated class files
[javac] -encoding <
encoding> Specify character encoding used by source files
[javac] -source <
release> Provide source compatibility with specified release
[javac] -target <
release> Generate class files for specific VM version
[javac] -help Print a synopsis of standard options

BUILD FAILED
D:\Jinal\Seminar\Latest\Sample\build.xml:14: Compile failed; see the compiler error output for details.

Total time: 329 milliseconds

and i have installed jdk 1.4.2
do i need to install jdk 1.5??? do this error mean this?

Sunil Kumar Gupta said...

Hi Jheel,

Did you check the build.xml provided in this example. It says

<javac destdir="./classes" source="1.5">

It means we are saying it to use Java 1.5. I would advice you to install jdk 1.5 or above.

Regards,
Sunil

jheel said...

hii
i have read all comments..i was getting some error which i have solved out by setting classpath
as u have give me that link for setting the classpath..
now when i build the build.xml file i m getting following error.

Buildfile: D:\Jinal\Seminar\Latest\Sample\build.xml
clean:
compile:
[javac] Compiling 1 source file to D:\Jinal\Seminar\Latest\Sample\classes
[javac] D:\Jinal\Seminar\Latest\Sample\src\org\xyz\Application.java:8: cannot access org.red5.server.adapter.ApplicationAdapter
[javac] bad class file: C:\Program Files\Red5\red5.jar(org/red5/server/adapter/ApplicationAdapter.class)
[javac] class file has wrong version 50.0, should be 49.0
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
[javac] import org.red5.server.adapter.ApplicationAdapter;
[javac] ^
[javac] 1 error

BUILD FAILED
D:\Jinal\Seminar\Latest\Sample\build.xml:14: Compile failed; see the compiler error output for details.

Total time: 2 seconds

please suggest what to do?
i m using red5 0.7 version

Sunil Kumar Gupta said...

Hi Jheel,

Here is the answer-

Java versions:

<... class file has wrong version 50.0, should be 49.0 ...>

The version difference suggests a setup problem: 49 is for Java 1.5, 50 is for Java 1.6. It's likely you have a non-1.6 Java in your PATH. Make sure each of the following commands shows 1.6:
javac -version
java -version

Make sure you are compiling your Java files with Java version 1.6. I think you need to change in build file where 1.5 is mentioned. Also check in Eclipse that Java 1.6is being used to compile the source.

Regards,
Sunil

jheel said...

hii sunil
thanks...
now the build successful...
but u have mention that jar file will be copied in to lib directory of web-inf ..but its not happening .....so i have copied it by my self
is it ok???
and we have generated Application.class and java file

dont we need to copy that two files also in web-inf??

Sunil Kumar Gupta said...

Hi Jheel,

Make sure that your jar file contains the Application class. You just need to place the jar file in your Red5 project WEB-INF/lib directory.

You dont need to copy any other file in WEB-INF/lib directory.

rids said...

hi this is very nice tutorial
now i m trying to do something like if i passed false as a parameter then i sholud get message connection is rejected
i m doing this in flex and eclipse
below is my actionscript code

package
{
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.events.NetStatusEvent;



public class Red5FirstClient extends Sprite
{
private var nc:NetConnection;

public function Red5FirstClient()
{
// new netconnection

nc = new NetConnection( );

// set encoding to old amf

nc.objectEncoding = ObjectEncoding.AMF0;

// netstatus event listening

nc.addEventListener( NetStatusEvent.NET_STATUS , netStatus );

// connect to red5, passing false as parameter

nc.connect( "rtmp://localhost/myapp" , false );

}

private function netStatus ( event:NetStatusEvent ):void
{

trace( event.info.code );

if ( event.info.code == "NetConnection.Connect.Rejected" )
{

// trace raeject message

trace( event.info.application );

}

}
}
}

and below is my Application.java file code

package org.red5.server.webapp.test;

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;

public class Application extends ApplicationAdapter
{


public boolean appStart ( )
{

return true;
}

public void appStop ( )
{

}

public boolean appConnect( IConnection conn , Object[] params )
{


boolean accept = (Boolean)params[0];

if ( accept==false )
{
rejectClient( "you passed false..." );
}

return false;
}

public void appDisconnect( IConnection conn , Object[] params )
{

}

}

the problem is
even if i pass false in

nc.connect( "rtmp://localhost/myapp" , false );

i m getting msg conection.success

can u help me please?

i have tried this from one tutorial

Sunil Kumar Gupta said...

Hi Rids,

When you are returning false from appConnect method. Connection success status should not come.


Regards,
Sunil

rids said...

hii Sunil
i have developed one chat application from the following refence

http://renaun.com/blog/2006/10/13/111/comment-page-1/#comment-485571

the problem is when one user presses logout button , userlist should be updated by deleting that user..but i m not able to do it ...

please give me some solution

RIA WORLD said...

hi sunil

can i develop a simple chat application using red5 server with out java file and chat having chating room also

RIA WORLD said...

hi sunil

can i develop a simple chat application using red5 server with out java file and chat having chating room also

Sunil Kumar Gupta said...

Hi RIA WORLD,

If you want something specific, you will have to create your own java files. If you just need a basic chat, then you can use the "oflaDemo" which comes with Red5. oflademo is sample chat source that comes bundled with red5. To customize, you will have to modify the Java files.

Regards,
Sunil

Anonymous said...

I installed red5 on a Debian system where apache2 is running now how can I use it.

Mobile Geek said...

Hi Anonymous,

You can start reading about Red5 from here.

Try the sample application i provided.

Anonymous said...

Hi! how to view the log messages generated by the application? Thanks

Bhawani Singh Bhati said...

Hi
Whenever i run my Red5 server i got this error: can you explain it, and why it is always, i can i get rid of this; please help me.

jvm 1 : at java.lang.Thread.run
Wrapper :<-- Wrapper Stopped

Please do explain im new in red5 config

Thank You,
Bhawani Singh Bhati

Mobile Geek said...

Make sure you have uninstalled the previous version of Red5 properly. It might be a corrupt installation..

Roy Villacorta said...

uhmm...i follow your tutorial and added all the needed jar files...but still it shows this error...

---------------------


Buildfile: E:\Eclipse Sample\Sample\Build.xml
clean:
compile:

[javac] E:\Eclipse Sample\Sample\src\org\xyz\Application.java:4: error: package org.apache.commons.logging does not exist
[javac] import org.apache.commons.logging.Log;

[javac] E:\Eclipse Sample\Sample\src\org\xyz\Application.java:47: error: cannot find symbol
[javac] super.roomDisconnect(conn);
[javac] ^
[javac] symbol: variable super
[javac] location: class Application
[javac] 16 errors

BUILD FAILED
E:\Eclipse Sample\Sample\Build.xml:16: Compile failed; see the compiler error output for details.

Total time: 3 seconds

---------------------------

can you please help me....

Roy Villacorta said...

uhmm...i follow your tutorial and added all the needed jar files...but still it shows this error...

---------------------


Buildfile: E:\Eclipse Sample\Sample\Build.xml
clean:
compile:

[javac] E:\Eclipse Sample\Sample\src\org\xyz\Application.java:4: error: package org.apache.commons.logging does not exist
[javac] import org.apache.commons.logging.Log;

[javac] E:\Eclipse Sample\Sample\src\org\xyz\Application.java:47: error: cannot find symbol
[javac] super.roomDisconnect(conn);
[javac] ^
[javac] symbol: variable super
[javac] location: class Application
[javac] 16 errors

BUILD FAILED
E:\Eclipse Sample\Sample\Build.xml:16: Compile failed; see the compiler error output for details.

Total time: 3 seconds

---------------------------

can you please help me....

sorry if i posted too many in this one...

Roy said...

please please please send me red5.jar...mine is corrupted. It doesn't have a source file. Please help me.

email: villcorta_roy@yahoo.com

please....

Vishu said...

Hi
I recently start red5 server side
coding and take this example , I am
making jar as we did many time using java bin not on eclipse and it created well but When I am running flash file for connection it through always onNetStatus: NetConnection.Connect.Rejected
Connection attempt rejected.
onNetStatus: NetConnection.Connect.Closed
Connection closed. error ..

Thanks

Vishu said...

Hi
I recently started Red5 server side
coding and I am using this example
I have made jar file by command using bin not by eclipse . but whenever I want to accessed that by flash
onNetStatus: NetConnection.Connect.Rejected
Connection attempt rejected.
onNetStatus: NetConnection.Connect.Closed
Connection closed. It throw these errors

Thanks

sunjune said...

Hi Sunil,
I am using Red5 as standalone server to record video streams. Would like to know when exactly(particular method call) after the recording is completed to convert them into mp4 format using xuggler.

Thanks in advance
Mohan

Howard said...

due to update of Red5 some of the code above is obsolete. I manage to tinker and fix these issues so that it works with latest Red5 v1.0.5.

1. Application.java:
change import org.red5.server.api.IScope; to import org.red5.server.api.scope.IScope;

2. ant build.xml
add classpath to include the latest red5 jar, in which red5 jars (red5-io-1.0.5-RELEASE.jar and red5-server-common-1.0.5-RELEASE.jar) can be downloaded from github (https://github.com/Red5/red5-server/releases/tag/v1.0.5-RELEASE, latest version as time of writing)

critical snippet (need to download commons-logging-1.2.jar and put into lib dir as well):

http://pastebin.com/P1ZpXUWw

3. change <bean id="web.scope" class="org.red5.server.WebScope"
init-method="register"> to <bean id="web.scope" class="org.red5.server.scope.WebScope"
init-method="register"> in red5-web.xml

full content of red5-web.xml (use this as skeleton, any extra garbage might cause runtime error):

http://pastebin.com/m9tJ3tJf

5. compile (command: ant jar) and put app.jar and classes under WEB-INF/lib, WEB-INF/classes respectively.

launch red5 and watch if any error msg occurs with your app.

Howard said...

fix wrong link above.

due to update of Red5 some of the code above is obsolete. I manage to tinker and fix these issues so that it works with latest Red5 v1.0.5.

1. Application.java:
change import org.red5.server.api.IScope; to import org.red5.server.api.scope.IScope;

2. ant build.xml
add classpath to include the latest red5 jar, in which red5 jars (red5-io-1.0.5-RELEASE.jar and red5-server-common-1.0.5-RELEASE.jar) can be downloaded from github (https://github.com/Red5/red5-server/releases/tag/v1.0.5-RELEASE, latest version as time of writing)

critical snippet (need to download commons-logging-1.2.jar and put into lib dir as well):

http://pastebin.com/P1ZpXUWw

3. change to in red5-web.xml

full content of red5-web.xml (use this as skeleton, any extra garbage might cause runtime error):

http://pastebin.com/TSqtU8yx

4. remove all the garbage in web.xml and put the following:

http://pastebin.com/rDt9KnNX

5. compile (command: ant jar) and put app.jar and classes under WEB-INF/lib, WEB-INF/classes respectively.

launch red5 and watch if any error msg occurs with your app.

Daily Technology Tips

Catch me at Mashable

PayPal

Sign up for PayPal and start accepting credit card payments instantly.

Blog Explosion


Bloglines

Blogrush


BlogsByCategory.com