red5建立第一个项目

来源:互联网 发布:淘宝如何设置关联宝贝 编辑:程序博客网 时间:2024/05/21 10:26

一,安装jdk

二,安装red5

三,修改配置文件

 1.在wepapps中创建新文件夹chapter2,将其他项目的 web-inf目录拷到该文件夹下面,修改web-inf下面的配置文件

2.修改red5-web.properties

webapp.contextPath=/chapter2
webapp.virtualHosts=*

3.修改red5-web

<?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-3.0.xsd                            
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">

<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.scope.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="first.Application" />   此处为自己的包下的类名字


</beans>


4. 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>vod</display-name>

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/chapter2</param-value>
</context-param>
    
    <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-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>

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



java代码:

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();// 传入的字符串转换成大写后返回
}
}



flex代码:


<?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">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>


<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var rtmpURL:String="rtmp://localhost/chapter2";
private var conn:NetConnection=new NetConnection();
private var isConnectSuccess:Boolean=false;
private var responder:Responder=new Responder(resultFun);

private function resultFun(object:String):void{
trace(object);
result.text=object.toString();
}
private function clickConnect(e:MouseEvent):void{
conn.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
conn.connect(rtmpURL);
}

private function click(e:MouseEvent):void{
invoke();
}

private function invoke():void{
if(isConnectSuccess){
conn.call("change",responder,str.text);//change 是服务器端方法名称
}else{
Alert.show("还没连接到服务器");
}
}

private function netStatus(e:NetStatusEvent):void{
trace(e.info.code);
if(e.info.code=="NetConnection.Connect.Success"){
isConnectSuccess=true;
}
}

]]>
</fx:Script>
<mx:Button x="224" y="175" label="调用服务器方法" click="this.click(event)"/>
<mx:TextInput x="129" y="145" id="str" width="212"/>
<mx:Label x="129" y="119" text="显示从服务器端返回的字符" id="result" width="160"
 fontSize="12"/>
<mx:Button x="129" y="175" label="连接服务器" click="this.clickConnect(event)"/>
</s:Application>


四,  在web-inf下面新建一个classes目录将java编译后的class包,放入classes,然后启动felx项目,启动red5就OK了



原创粉丝点击