今天忙了一天,目的很简单,就是把red5整合到tomcat中,通过简单访问可以请求到数据。
下面简单记述一下过程:
1,下载需要的red5.red5官网http://www.red5.org/,下载1.0.rec里的两个zip包,如图。
2,将下载的包解压后,将red5-war-1.0-RC1包里的ROOT.war放到tomcat的webapps下。将原来的ROOT文件夹改名为ROOT_t,便于区别,启动tomcat。当启动完毕后就出现一个新的ROOt文件夹。该文件夹备用。
3,在Eclipse中新建项目。我这里命名为chapter2,然后到ROOT文件夹下 WEB-INF下面拷贝lib目录到相同位置,并拷贝文件适当修改。还要拷贝red5.jar.下面先修改web.xml.具体如下
<?xml version="1.0" encoding="UTF-8" ?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>chapter2</display-name> <context-param> <param-name>webAppRootKey</param-name> <param-value>/chapter2</param-value> </context-param> <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>contextConfigLocation</param-name> <param-value>WEB-INF/classes/*-web.xml</param-value> </context-param> <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>/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>/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> <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>
4,进入Root/WEB-INF/classes文件夹里,拷贝所有配置文件,如下.
修改root-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> <!-- ROOT web context --> <bean id="web.context.chapter2" class="org.red5.server.Context"> <property name="scopeResolver" ref="red5.scopeResolver" /> <property name="clientRegistry" ref="global.clientRegistry" /> <property name="serviceInvoker" ref="global.serviceInvoker" /> <property name="mappingStrategy" ref="global.mappingStrategy" /> </bean> <bean id="web.scope.chapter2" 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.chapter2" /> <property name="handler" ref="web.handler.chapter2" /> <property name="contextPath" value="${webapp.contextPath}" /> <property name="virtualHosts" value="${webapp.virtualHosts}" /> </bean> <bean id="web.handler.chapter2" class="first.Application" singleton="true" /> <bean id="flv.service" class="chapter7.StreamService" singleton="true"> </bean> </beans>
注意此处的chapter2,是我们的项目名称。red5-web.properties放置在web-info下,内容是
webapp.contextPath=/chapter2 webapp.virtualHosts=localhost,localhost:8088,127.0.0.1:8088
5,修改red5-core.xml 。
具体如下:
<!-- RTMP Mina Transport --> <bean id="rtmpTransport" class="org.red5.server.net.rtmp.RTMPMinaTransport" init-method="start" destroy-method="stop"> <property name="ioHandler" ref="rtmpMinaIoHandler" /> <property name="connectors"> <list> <bean class="java.net.InetSocketAddress"> <constructor-arg index="0" type="java.lang.String" value="127.0.0.1" /> <constructor-arg index="1" type="int" value="1935" /> </bean> <!-- You can now add additional ports and ip addresses <bean class="java.net.InetSocketAddress"> <constructor-arg index="0" type="java.lang.String" value="0.0.0.0" /> <constructor-arg index="1" type="int" value="1936" /> </bean> --> </list> </property> <property name="receiveBufferSize" value="65536" /> <property name="sendBufferSize" value="271360" /> <property name="connectionThreads" value="4" /> <property name="ioThreads" value="16" /> <!-- This is the interval at which the sessions are polled for stats. If mina monitoring is not enabled, polling will not occur. --> <property name="jmxPollInterval" value="1000" /> <property name="tcpNoDelay" value="true" /> </bean>
注意: tomcat里面添加太多的red5服务,会造成tomcat内存泄露,这么时候就要修改tomcat的启动内存bin/catalina.bat
Win:
set JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx1024m
linux:
JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx1024m -XX:PermSize=256M -XX:MaxNewSize=512m -XX:MaxPermSize=512m"
如果要修改webapps下的项目启动的优先级,就在 conf\Catalina\localhost 加上一个 项目名.xml 的文件
文件内容:
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true" />
6 然后我们做相应的响应代码。
package first; import org.red5.server.adapter.ApplicationAdapter; import org.red5.server.api.IConnection; public class Application extends ApplicationAdapter{ public boolean appConnect(IConnection conn,Object[] args) { System.out.println("链接"); return true; } public String change(String str){ System.out.println("客户端调用服务器端方法"); return str.toUpperCase(); } }
package chapter7; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.red5.server.api.IScope; import org.red5.server.api.Red5; import org.springframework.core.io.Resource; public class StreamService { /** * Getter for property 'listOfAvailableFLVs'. * * @return Value for property 'listOfAvailableFLVs'. */ public Map getListOfAvailableFLVs() { IScope scope = Red5.getConnectionLocal().getScope(); Map<String, Map> filesMap = new HashMap<String, Map>(); Map<String, Object> fileInfo; try { Resource[] flvs = scope.getResources("streams/*.flv"); if (flvs != null) { for (Resource flv : flvs) { File file = flv.getFile(); Date lastModifiedDate = new Date(file.lastModified()); String lastModified = formatDate(lastModifiedDate); String flvName = flv.getFile().getName(); String flvBytes = Long.toString(file.length()); fileInfo = new HashMap<String, Object>(); fileInfo.put("name", flvName); fileInfo.put("lastModified", lastModified); fileInfo.put("size", flvBytes); filesMap.put(flvName, fileInfo); } } Resource[] mp3s = scope.getResources("streams/*.mp3"); if (mp3s != null) { for (Resource mp3 : mp3s) { File file = mp3.getFile(); Date lastModifiedDate = new Date(file.lastModified()); String lastModified = formatDate(lastModifiedDate); String flvName = mp3.getFile().getName(); String flvBytes = Long.toString(file.length()); fileInfo = new HashMap<String, Object>(); fileInfo.put("name", flvName); fileInfo.put("lastModified", lastModified); fileInfo.put("size", flvBytes); filesMap.put(flvName, fileInfo); } } } catch (IOException e) { e.printStackTrace(); } return filesMap; } private String formatDate(Date date) { SimpleDateFormat formatter; String pattern = "dd/MM/yy H:mm:ss"; Locale locale = new Locale("en", "US"); formatter = new SimpleDateFormat(pattern, locale); return formatter.format(date); } }
red5 整合到tomcat中(二)
相关推荐
red5 与 tomcat项目集成
对以前上传的Red5 0.9与现有tomcat项目整合进行了修正
本文介绍tomcat整合red5,以及red5的优势,Red5 Server使用Java技术开发的服务器软件.从多个方面支持流媒体功能
Red5 0.9与现有tomcat项目整合,并实现flex播放视频 修正:将logback.xml的标签去掉,根据情况修改level 将:red5-web.xml名修改为myApp-web.xml,内容修改为 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" ...
详细整合请看博客, 希望可以帮到你们。 http://blog.csdn.net/dao2012/article/details/51700367
开源流媒体服务器与tomcat的整合方案,不过是英文的。
red5 1.0 final 与 tomcat 整合 ,导入myeclipse可以直接使用。
red5整合到个人tomcat,并添加了oflaDemo示例。
red5与tomcat整合所需要用到的war包
博文链接:https://kyo-cc.iteye.com/blog/195969
我这个是在Red Hat Enterprise Linux 5下做的
最新Red5 1.0.6 web版,1.0.2-1.0.7M4通用,替换以下jar包到对应版本即可。可. red5-client-1.0.6-RELEASE.jar red5-io-1.0.6-RELEASE.jar red5-server.jar red5-server-common-1.0.6-RELEASE.jar red5-service.jar
要学好linux,那么命令的重要性不言而喻,而此书从最...Red Hat Linux下配置Tomcat+JSP+Apache服务器的步骤.txt Linux 下 Apache 与 Tomcat 整合的简单方法.txt LINUX系统root密码破解步骤.txt linux忘记root密码.txt
到mysql官网下载red hat enterprise linux / oracle linux版本到本地,解压后上传到服务器目录 查看mysql相关的文件是否存在 find / -name mysql 删除mysql相关的文件 find / -name mysql|xar
1.2.7 功能强大的flv流媒体服务器red5 24 1.3 门户网站开发指导思想 26 1.4 ssh 2组合框架—门户网站开发之首选 28 1.4.1 mvc混血宠儿struts 2 28 1.4.2 幕后的财政部长spring 2.5 30 1.4.3 orm中间件香馍馍...