Background
Creating the most basic of server applications in Red5 is pretty easy. In fact, we're not going to write any code at all. We're going to take advantage of the Red5 Application Generation built into the Red5 Plugin to do all the work for us.
Prerequisites
You will need the complete Red5 user development environment.
Generating your project
Let's get started.
- Launch Eclipse. You should be in the Java EE perspective, and the Project Explorer view should be opened.
- Right click in the Project Explorer view and choose New -> Dynamic Web Project

- In the New Dynamic Web Project panel, enter a Project Name of "SimpleRed5Project".
- In the Configuration section, click on the Modify button

- In the Project Facets panel that appears, check the box next to Red5 Application Generation, then click the OK button.

- Click on the Finish button

- In the Package Explorer view you should now see two new projects: SimpleRed5Project and SimpleRed5ProjectClient. Believe it or not, but these are fully functional server and client applications! As far as development is concerned, we're done. Let's take a quick look at what was just generated.
What was generated
We have two projects, SimpleRed5Project and SimpleRed5ProjectClient. Examine the SimpleRed5Project server-side project first. Navigate through the project tree to familiarize yourself with the layout.

In the server project, the main things you should focus on are Application.java, which is the core of our new server application, and the contents of WEB-INF. Application.java is actually more complicated than it needs to be for a trivial example. If you wanted to, you could not define any methods at all. Merely extending ApplicationAdapter would be sufficient to have a working -- and quite useful -- server application.

Under WEB-INF you'll see files: red5-web.properties, red5-web.xml, and web.xml. If you've done Tomcat work before then web.xml should look vaguely familiar. The file red5-web.xml is where the Spring configuration for our application is located.
Over in the SimpleRed5ProjectClient project, there is a single source file for the application. If you're familiar with Flex client development then this should be easy to understand, even if you haven't used the NetConnection API before. If you are new to Flex and/or AS3, you should familiarize yourself with Flex after finishing this guide.

In the future you'll learn what each part of these files mean. For now it will be more fulfilling to see the projects in action, so let's give this a test.
Testing your projects
- First, we need to deploy your application to the Red5 server instance. Select the SimpleRed5Project project, right click on it, and choose Debug as -> Debug on Server

- Since this is the first time running the server application, Eclipse will prompt us under which server runtime we wish to run the application. Let's choose the Red5 Server Runtime and check the box next to "Always use this server when running this project", and then click the Finish button.

- Eclipse should then deploy your application to Red5 and start up the server. Remember, if you can an error message that the port is already in use, don't panic. Just stop the server (even it appears stopped) and try to do a debug run of the application again.
- Once the server application is running, the Server view should look like this:

- In the Project Explorer view, right click on the SimpleRed5ProjectClient, and choose Debug As -> Flex Application

- Eclipse should launch your default web browser, and if things went right you should see the following Alert dialog:

9 comments:
Hi ,
I'm from Iran with week skill in English Writting ;)
I have Final project ( Electronic Voting with flex and red5 server )
when I debug "TestingRed5" , eclipse Alert me that The port :5080 in use
and when I debug "TestingRed5Client" in my browser display " unsuccessful Connection , please help me " arash.raji@gmail.com "
@arash The most common thing that happens to people is they get into a situation where they already have a Red5 process running, and the attempt to start a second one results in a "port in use"/BindException. If that's the case, the solution is to either stop the server from Eclipse first or kill the running Red5 java process. The procedure for killing the process will depend on your operating system. On Mac OS X, you can try the following:
1.) Open Terminal
2.) Type 'ps auxw | grep red5 | grep -v grep'
3.) If any processes are listed, note the process id
4.) Type 'kill PID', where PID is the process ID you noted above
5.) Then try to launch the Red5 server from Eclipse again.
There is another possibility that some other program is using port 5080. To identify which process that might be on OSX, you can use the following command in Terminal:
sudo lsof -i:5080
That will list any process using port 5080. You can then kill that process if you don't need it. If you have something else using that port, you'll have to reconfigure that process or red5 to use another port.
Thanx Alex,
terminal that you typed means " command prompt" ?
I typed sodu lsof "-i:5080" in terminal , but alert me syntax error!
I stoped red5 sed5 server manulaly , but i have problem again with"port in use"
!!!!!!!!
Terminal is the Mac OS X utility that gives you a command-line shell. If you are using Windows, you have command prompt. But there is no lsof utility for Windows. Instead you can try a SysInternals tool such as TCP View to identify which program is using a port:
http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx
Thanks again, Alex
I wanna replace FMS with Red5 media server in my project, How can I replace "connect to FMS" in my Flex source code to "connect to Red5"?
and how can send to you my source code?
and can I using SWF file ( for connect to red5 ), and put it in Apache/htdocs , and then use it for my connection in my Adobe Flex Builder 3 framework?
(without using Eclipse IDE)
If you have a working Flex client that can work with FMS, you can often simply replace the connection URL with the URL to your Red5 application.
Yes, you can compile your Flex application using the command-line SDK and deploy it to apache.
You will probably have better luck asking your questions on a question and answer site like http://stackoverflow.com/ where many people will see your questions and be able to answer you. When you post here, its probably only me who will see it.
Hi Alex, how can I find the client side'code of the fitc demo (video conference) that is locate in red5 's sample, and can I use my actionscript'code (client side code for connect to fms) for connecting to red5?
I believe the client side for that demo was written in flash and is as2. You probably don't want to use it as a basis for any new project. However if you are interested in that, head over to the red5 user mailing list archives. I believe that question has been asked and answered many times on the mailing list.
Post a Comment