研究完red5的demo之后,我们可以手动写个小例子,试试连接red5。
准备步骤,打开MyEclipse和Flex Builder。MyEclipse做一个web工程,写一个简单的Java文件
package org.red5.test; import org.red5.server.adapter.ApplicationAdapter; import org.red5.server.api.IClient; import org.red5.server.api.IConnection; import org.red5.server.api.IScope; public class Application extends ApplicationAdapter { private IScope app = null; public boolean appStart(IScope __app) { app = __app; super.appStart(app); return true; } @Override public synchronized boolean connect(IConnection conn, IScope scope, Object[] params) { System.out.println("connect"); IClient client = conn.getClient(); String uid = client.getId(); System.out.println("connect->uid:" + uid); System.out.println("welcome to red5 world !"); return true; } }
然后将整个WebRoot 拷贝到red5目录下面的webapps,然后在WEB-INF目录下补充上 red5-web.xml 和 red5-web.properties 文件,将red5-web.xml 里面的修改为
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="/WEB-INF/red5-web.properties" /> </bean> <bean id="web.context" class="org.red5.server.Context" autowire="byType" /> <bean id="web.scope" class="org.red5.server.WebScope" init-method="register"> <property name="server" ref="red5.server" /> <property name="parent" ref="global.scope" /> <property name="context" ref="web.context" /> <property name="handler" ref="web.handler" /> <property name="contextPath" value="${webapp.contextPath}" /> <property name="virtualHosts" value="${webapp.virtualHosts}" /> </bean> <bean id="web.handler" class="org.red5.test.Application" singleton="true" /> </beans>
然后修改web.xml文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Red5App</display-name>
<context-param>
<param-name>Red5App</param-name>
<param-value>/red5_app2</param-value>
</context-param>
<listener>
<listener-class>org.red5.logging.ContextLoggingListener</listener-class>
</listener>
<filter>
<filter-name>LoggerContextFilter</filter-name>
<filter-class>org.red5.logging.LoggerContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggerContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>
<display-name>SecurityTest</display-name>
<servlet-name>SecurityTest</servlet-name>
<servlet-class>org.red5.demos.oflaDemo.SecurityTest</servlet-class>
</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>
<!--
<servlet-mapping>
<servlet-name>SecurityTest</servlet-name>
<url-pattern>/securitytest</url-pattern>
</servlet-mapping>
-->
<!--
<security-constraint>
<web-resource-collection>
<web-resource-name>Forbidden</web-resource-name>
<url-pattern>/streams/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
-->
</web-app>
重启red5,没有错误可以说明部署成功了。
开发一个客户端去连接red5,可以使用Flex 工具编写,不管你是做Web application 还是 Desktop application其实都一样。代码: