Red5 + flex Application Development

Source: Internet
Author: User

Red5 applications are divided into two parts: server and client. Eclipse is used as the development environment, and Flash builder4.6 is used for client flex development. Note that red5 only supports jdk1.6. The following is a simple red5 application to implement communication between the client and the server.

1. Server

Set the eclipse workspace to D: \ Program Files \ red5 \ webapps and create a Java project named "hellored5.

In properties-> JAVA build path-> libraries-> Add external jars..., add the dependency library red5. jar, which is in the red5 installation directory.

Set the compile output directory to hellored5/WEB-INF/classes.

Copy the DOC/template/MyApp/WEB-INF directory to the project directory.

After completing the preceding steps, the project directory structure is as follows:

Add a Java class named hellored5, which is simple and inherited from applicationadapter.

Hellored5.java

package sample;import org.red5.server.adapter.ApplicationAdapter;public class HelloRed5 extends ApplicationAdapter {public String sayHello() {return "Hello, red5!";}}

Modify several configuration files below

Red5-web.properties

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

Web. xml

...<context-param><param-name>webAppRootKey</param-name><param-value>/helloRed5</param-value></context-param>...

Red5-web.xml,

<bean id="web.handler"     class="sample.HelloRed5" singleton="true" />

Now all the work on the server is done.

2. Client

Use flash builer4.6 to create a flex project named "hellored5client" and use netconnection to communicate with the server. The function of the client is very simple. A button and a lable control are placed on the interface. After clicking the button, the string "Hello, red5!" obtained from the server is displayed! ".

Hellored5client. mxml

<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "minwidth =" 955 "minheight =" 600 "creationcomplete =" Init (); "> <FX: declarations> <! -- Place non-visual elements (e.g., services, value objects) Here --> </FX: declarations> <FX: SCRIPT> <! [CDATA [import flash.net. netconnection; import MX. controls. alert; private var NC: netconnection; Private function Init (): void {NC = new netconnection (); NC. addeventlistener (netstatusevent. net_status, connecthandler); NC. client = This; NC. connect ("rtmp: // localhost/hellored5");} private function sayhello (): void {NC. call ("sayhello", new Responder (okhandle, failurehandle);} public function okhandle (Result: string): Vo Id {message. TEXT = result;} public function failurehandle (Result: string): void {alert. show (result, "error");} private function connecthandler (EVT: netstatusevent): void {If (evt.info. code! = "Netconnection. connect. success ") {alert. show ("Code:" + evt.info. code, "error"); NC. removeeventlistener (netstatusevent. net_status, connecthandler) ;}} public function onbwdone (): void {}// Note: This function cannot be less protected function button#clickhandler (Event: mouseevent ): void {// todo auto-generated method stubsayhello () ;}]> </FX: SCRIPT> <s: button x = "55" Y = "43" label = "Say hello" Click = "button#clickhandler (event)"/> <s: label id = "message" x = "159" Y = "44"/> </S: Application>

Note:

nc.client = this;public function onBWDone():void{}

No. Otherwise, the following error is prompted.

Error #2044: unprocessed asyncerrorevent :. TEXT = Error #2095: flash.net. netconnection cannot call the onbwdone callback. Error = referenceerror: Error #1069: The onbwdone attribute cannot be found on hellored5client, and no default value exists.

3. Run

Start red5 and open the compiled hellored5client.html file on the browser, and click "Say hello". The result is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.