Flash code:
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
//创建一个NetConnection对象
var nc:NetConnection = new NetConnection();
//给nc对象绑定一个事件句柄,用来跟踪netStatus
nc.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
//完成句柄对应的函数netStauts
function netStatus(event:NetStatusEvent):void
{
trace(event.info.code);
}
//开始连接red5服务器承载的示范应用
nc.connect("rtmp://169.254.80.208/firstapp");
Java:
Application.java
/**
*
*/
package com.red5app;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.scope.IScope;
/**
* @author L
*
*/
public class Application extends ApplicationAdapter {
@Override
public boolean appStart(IScope arg0) {
return true;
}
@Override
public void appStop(IScope arg0) {
}
}
red5-web.properties
webapp.contextPath=/firstapp
webapp.virtualHosts=169.254.80.208
red5-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-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="com.red5app.Application" />
</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>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-web.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>webAppRootKey</param-name>
<param-value>/firstapp</param-value>
</context-param>
<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>