Red5学习笔记(一)Red5应用创建与发布

2 篇文章 0 订阅
应用创建:
1、新建项目
2、 新建目录WEB-INF,将Red5安装目录下doc\templates\myapp\WEB-INF目录的四个文件复制到WEB-INF中
3、在WEB-INF新建源目录src和编译输出目录classes
下面创建一个空白应用
package com.red5app;
import org.red5.server.adapter.ApplicationAdapter;
/**
 * 在Red5的服务器端类体系里,每一个监听的应用实例都需要继承类ApplicationAdapter
 * 项目需要引用Red5安装目录下的red5.jar
 * @author Administrator
 */

public  class Application  extends ApplicationAdapter{
     /**
     * 实现appStart和appStop两个必要的方法
     **/

     public  boolean appStart()
    {
         return true;
    }
    
     public  void appStop()
    {
        
    }
}  

发布应用:
1、编译当前项目代码
2、修改WEB-INF下的四个配置文件
        文件log4j.properties是用来指定log4j的工作方式,一般情况下可以不修改;
        文件red5-web.properties是用来指定应用程序的目录名和监听的IP地址,根据实际修改
     webapp.contextPath = /firstapp
     webapp.virtualHosts =localhost,   127. 0. 0. 1
         文件red5-web.xml是用来指定该应用程序在webapps目录下加载的程序集以及相关的beans
< ?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 = "com.red5app.Application" 
        singleton = "true"  / >
     < ! -- <bean id = "myhandler.service" 
         class = "the.path.to.my.ServiceHandler" 
        singleton = "true"  / >
     -- >
< /beans >
         文件web.xml是用来指定该应用在运行时的Context参数和监听器
< ?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 >firstapp < /display -name >
     <context -param >
         <param -name >globalScope < /param -name >
         <param -value > default < /param -value >
     < /context -param >
     <context -param >
         <param -name >contextConfigLocation < /param -name >
         <param -value > /WEB -INF /red5 - *.xml < /param -value >
     < /context -param >
     <context -param >
         <param -name >locatorFactorySelector < /param -name >
         <param -value >red5.xml < /param -value >
     < /context -param >
     <context -param >
         <param -name >parentContextKey < /param -name >
         <param -value > default.context < /param -value >
     < /context -param >
    
     <context -param >
         <param -name >log4jConfigLocation < /param -name >
         <param -value > /WEB -INF /log4j.properties < /param -value >
     < /context -param >
    
     <context -param >
         <param -name >webAppRootKey < /param -name >
         <param -value > /firstapp < /param -value >
     < /context -param >
     < ! --由于没有指定监听器,因些需要将listener节点全部删除,避免启动时出错
     <listener >
         <listener - class >org.springframework.web.util.Log4jConfigListener < /listener - class >
     < /listener >
    
     <listener >
         <listener - class >org.springframework.web.context.ContextLoaderListener < /listener - class >
     < /listener >
     -- >
     < ! -- remove the following servlet tags  if you want to disable remoting  for  this application  -- >
    < ! -- 如果不需要对应用远程调试,需要将servlet节点全部删除
     <servlet >
         <servlet -name >gateway < /servlet -name >
         <servlet - class >org.red5.server.net.servlet.AMFGatewayServlet < /servlet - class >
     < /servlet >
    
     <servlet -mapping >
         <servlet -name >gateway < /servlet -name >
         <url -pattern > /gateway < /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>
3、在Red5安装目录的webapp目录下创建目录firstapp,在firstapp目录下创建WEB-INF,然后将工程目录下的WEB-INF里的classes文件夹和4个配置文件全部复制到firstapp下的WEB-INF里
4、重启Red5服务
查看Red5安装目录log下的red5_services.log文件,当出现如下提示说明应用成功被Red5服务器加载:
INFO   | jvm 1    | 2014/09/14 22:02:34 | [INFO] [Launcher:/firstapp] org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in 

客户端连接:(以AS3为例)
AS3与Red5服务器进行通信主要有:NetConnection、NetStream、SharedObject。调用顺序如下图所示:





    
    
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.SharedObject;
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
var so:SharedObject;
function netStatus(event:NetStatusEvent):void
{
trace("event.info.code:"+event.info.code);
switch(event.info.code)
{
case "NetConnection.Connect.Success":
var so:SharedObject = SharedObject.getRemote("UserSO",nc.uri,true);
break;
}
}
nc.connect("rtmp://127.0.0.1/firstapp");//连接时地址不需要端口号


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值