您的位置:首页 > 运维架构 > Tomcat

将red5集成到Tomcat服务器中

2009-08-11 15:07 309 查看
http://hi.baidu.com/cqmking/blog/item/8d7cc1fb777f741f6d22ebc4.html
将red5集成到Tomcat服务器中
2009-07-03 17:00
http://dl.fancycode.com/red5/0.6.3/war/ 下载的是java5目录下的三个war(ROOT.waradmin.warecho.war)中的ROOT.war) 并下载安装 win:setup-red5-0.6.3.exe

1.在Eclipse下新建一个web应用,起名叫myApp。

2.将ROOT.war解压。将其目录下web-info/lib目录下的jar全部拷贝到myApp对应的lib中。拷贝red5安装目录的red5.jar到myApp/WEB-INFO/lib目录下。这样spring框架与red5需要的包都导入了

3.将ROOT.war解压后的文件夹中WEB-INFO/classes/目录下的除echo-web.xml,admin-web.xml,SOSample-web.xml,oflaDemo-web.xml,web.xml五个无文件外的其他文件拷贝到myApp的src下。并修改所有文件中的端口5080都改为8080。我安装tomcat时选择的9090所以 对应位置改为9090。

4.在src中新建一个自己项目的myApp-web.xml内容照着没要的文件改,如对应oflaDemo-web.xml文件改。

文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

<!-- SOSample -->
<bean id="myApp.context" class="org.red5.server.Context" autowire="byType" />

<bean id="myApp.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="myApp.context" />
<property name="handler" ref="myApp.handler" />
<property name="contextPath" value="/myApp" />
<property name="virtualHosts"
value="*,localhost, localhost:9090, 127.0.0.1:9090" />
</bean>

<bean id="myApp.handler" class="red5.example.red5server.Application" />

</beans>

红色部分为自己的应用服务器类。

7.修改web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
** For use with servlet v2.5 replace the lines above with these
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-->
<context-param>
<param-name>globalScope</param-name>
<param-value>default</param-value>
</context-param>

<context-param>
<param-name>parentContextKey</param-name>
<param-value>default.context</param-value>
</context-param>

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

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/*-web.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<listener>
<listener-class>org.red5.server.war.WarLoaderServlet</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
<servlet-name>gateway</servlet-name>
<servlet-class>org.red5.server.net.servlet.AMFGatewayServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>rtmpt</servlet-name>
<servlet-class>org.red5.server.net.rtmpt.RTMPTServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>gateway</servlet-name>
<url-pattern>/gateway</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>/idle/*</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>/close/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>login.html</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>

<security-constraint>
<web-resource-collection>
<web-resource-name>Forbidden</web-resource-name>
<url-pattern>/WEB-INF/*</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>Forbidden</web-resource-name>
<url-pattern>/persistence/*</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>

<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>

6.在src中新建包red5.example.red5server。在包中新建类Application:内容如下

package red5.example.red5server;

import org.red5.server.adapter.ApplicationAdapter;

public class Application extends ApplicationAdapter {

public String login(){
return "Welcome to Chat Servers";
}

}

然后部署到tomcat。启动不报错则成功。

接下来编写flex客户端。

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontFamily="Arial">
<mx:Script>
<![CDATA[
public function connect():void
{
var nc:NetConnection = new NetConnection();
trace("链接服务器......");
nc.connect("rtmp://localhost/myApp");
nc.call("login",new Responder(_onGet,_onError));
}

private function _onError(obj:Object):void {
text1.text =""+ obj;
}

private function _onGet(obj:Object):void {
text1.text =""+ obj;
}
]]>
</mx:Script>
<mx:Button x="118" y="216" label="按钮" fontFamily="Verdana" fontSize="12" click="connect()" id="button1"/>
<mx:Label x="119" y="149" text="Label" width="245" color="#F8F2F8" height="23" fontSize="15" id="text1"/>
</mx:Application>

将编译后的flex工程下bin-debug文件夹下的文件全部复制到tomcat/webapps/myApp中。
访问:http://localhost:9090/myApp/red5Client.html
http://localhost:9090/myApp/red5Client.swf

即可测试 如图:





有时启动,运行链接失败。 发现是我的tomcat中webapps文件夹下的多个red5项目造成的。

测试的时候最好将其他的red5相关项目移除。也不知道具体是怎么回事!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: