- 浏览: 85179 次
- 性别:
- 来自: 北京
最新评论
-
zhulongxia:
您好,请问您的服务端的配置和用flex写客户端的配置一样么?还 ...
Red5 Client 调用 Red5 Server -
zhaoleiJE:
public static String toMPTree(S ...
jave -
zouwu85:
你好,你这个能录制网络上的flv小游戏的数据吗?
使用Red5 录制视频 -
emilyHong:
不过有没有多条线的?
js曲线图 -
amssy_zhu:
很好,正准备开发这样的系统
使用Java实现Comet风格的Web应用
package ChatSystem;
import java.util.List;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.adapter.ApplicationAdapter ;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.IPlaylistSubscriberStream;
import org.red5.server.api.stream.IStreamAwareScopeHandler;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.api.so.ISharedObject ;
public class CSApplication extends ApplicationAdapter implements
IStreamAwareScopeHandler, IPendingServiceCallback {
public String adminUserName = ” Admin”;
public String adminUserPassword = “pwd”;
public String userName;
public String userPwd;
//private boolean persistent;
public String URL;
String[] clientsByID = new String[100];
private static final Log log = LogFactory.getLog (CSApplication.class);
public boolean appStart(IScope scope) {
// initiating the handler here
log.info(”Client is connected “);
log.info(”Creating Shared Objects “);
createSharedObject(scope, “adminStatus”, true);
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.removeAttributes();
adminStatus_so.setAttribute(”adminIsIn”, false);
createSharedObject(scope, “userList”, true);
//ISharedObject userList_so = getSharedObject(scope, “userList”);
//userList_so.setAttribute(”List”,list);
//userList_so.removeAttributes();
return true;
}
@Override
public boolean appConnect(IConnection conne, Object[] params) {
IServiceCapableConnection service = (IServiceCapableConnection)
conne;
log.info(”Client is connected ” + conne.getClient().getId() + ”
conne ” + conne);
log.info(”Setting stream id as : “+ getClients().size()); //
just a unique number
service.invoke(”setId”, new Object[]{conne.getClient().getId()},
this);
return true;
}
//@Override
public boolean appJoin(IClient client, IScope scope, String
userName, String userPwd) {
log.info(”Client joined app ” + client.getId());
IConnection conne = Red5.getConnectionLocal();
client.setAttribute(”userName”,userName);
client.setAttribute(”userPwd”,userPwd);
ISharedObject UserList = getSharedObject(scope,”UserList”);
if (client.getAttribute(userName)== “__mainPage__”){
//ISharedObject UserList = getSharedObject(scope,”UserList”);
UserList.setAttribute(client.getId(),userName);
}
else if(userName == adminUserName){
if(userPwd == adminUserPassword){
String IDofClient = conne.getClient ().getId();
removeFromList(IDofClient);
//URL notifications
URLNotify(IDofClient,URL);
//<- Find the Notification way
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.setAttribute(”adminIsIn”, true);
this.userName = userName;
}
rejectClient(conne.getClient());
}
return true;
}
public void putMeInLine(String userID, String userName) {
log.info(”putMeInLine:”+userID+”,”+userName);
//ISharedObject UserList_so = getSharedObject(scope,”UserList”);
clientsByID[1]= userID;
addToLine(userID, userName);
}
public String URLNotify(String clientID,String URL){
// write a Iterator to find the specied userId and then send him the URL
return URL;
}
public void addToLine(String userID,String userName){
ISharedObject UserList_so = getSharedObject(scope,”UserList”);
UserList_so.setAttribute(userID,userName);
}
public void removeMeFromLine(String userId){
ISharedObject UserList_so = getSharedObject(scope,”UserList”);
UserList_so.removeAttribute(userId);
}
public boolean removeFromList(String ID)
{
log.info(”removeFromList:”+ID);
ISharedObject userList_so = getSharedObject(scope, “userList”);
//list = userList_so.getAttributes(”list”);
Object[]list = new Object[100];
//list = userList_so.getData(ID);
for (int i=0; i<list.length; i++) {
list[i] = userList_so.getAttribute(ID);
}
if (userList_so.hasAttribute(ID)){
for (int i=0; i<list.length; i++) {
if (list[i] == userList_so.getAttribute(ID)) {
this.removeAttribute(ID);
}
}
return true;
}return false;
}
public String setName(String name){
log.info(”setName:”+name);
userName= name;
return “ack”;
}
public String setDomainName(String name) {
log.info(”setDomainName:”+name);
ISharedObject userList_so = getSharedObject(scope, “userList”);
userList_so.setAttribute(”userdomainname”,name);
return “ack”;
}
public boolean userBell(String userId){
IConnection current = Red5.getConnectionLocal();
Iterator<IConnection> itr = scope.getConnections();
while ( itr.hasNext()) {
IConnection conne = itr.next();
IServiceCapableConnection service = (IServiceCapableConnection)
conne;
if (conne.equals(current))
service.invoke(”userBell”);
}
return true;
}
public void streamPublishStart(IBroadcastStream stream) {
// Notify all the clients that the stream had been started
log.debug(”Starting the Stream Broadcast: “+stream.getPublishedName());
IConnection current = Red5.getConnectionLocal();
Iterator<IConnection> itr = scope.getConnections();
while (itr.hasNext()) {
IConnection conne = itr.next();
if (conne.equals (current))
// Current client Should not be Notified
continue;
if (conne instanceof IServiceCapableConnection) {
((IServiceCapableConnection) conne).invoke(”newStream”, new
Object[]{stream.getPublishedName()}, this);
log.debug(”Now sending notification to “+conne);
}
}
}
public void streamBroadcastStart(IBroadcastStream stream) {
}
public void streamBroadcastClose(IBroadcastStream stream) {
}
public void streamSubscriberStart(ISubscriberStream stream) {
}
public void streamPlaylistItemStop(IPlaylistSubscriberStream stream,
IPlayItem item) {
}
public void streamPlaylistItemPlay(IPlaylistSubscriberStream stream,
IPlayItem item, boolean isLive) {
}
public void streamPlaylistVODItemPause(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {
}
public void streamPlaylistVODItemResume(IPlaylistSubscriberStream
stream, IPlayItem item, int position) {
}
public void streamPlaylistVODItemSeek(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {
}
public void streamSubscriberClose(ISubscriberStream stream) {
}
/**
* Get streams. called from client
*
* @return iterator of broadcast stream names
*/
public List<String> getStreams(){
IConnection conne = Red5.getConnectionLocal();
return getBroadcastStreamNames(conne.getScope());
}
/**
* Handle callback from service call.
*/
public void resultReceived(IPendingServiceCall call) {
log.info(”Received result ” + call.getResult() + ” for ” +
call.getServiceMethodName());
}
public void appDisconnect(IConnection conne,IBroadcastStream
stream,IScope scope) {
log.info(”Application is disconnected “);
IClient client = conne.getClient();
if (client.equals(adminUserName)&& scope == conne.getScope()){
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.beginUpdate();
adminStatus_so.setAttribute(”adminIsIn”, false);
stream.close();
conne.close();
super.disconnect (conne,scope);
adminStatus_so.endUpdate();
}
else
{
ISharedObject userList_so = getSharedObject(scope, “userList”);
userList_so.beginUpdate();
removeFromList( conne.getClient().getId());
stream.close();
conne.getClient().disconnect();
super.disconnect(conne,scope);
userList_so.endUpdate();
}
}
}
import java.util.List;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.adapter.ApplicationAdapter ;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.IPlaylistSubscriberStream;
import org.red5.server.api.stream.IStreamAwareScopeHandler;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.api.so.ISharedObject ;
public class CSApplication extends ApplicationAdapter implements
IStreamAwareScopeHandler, IPendingServiceCallback {
public String adminUserName = ” Admin”;
public String adminUserPassword = “pwd”;
public String userName;
public String userPwd;
//private boolean persistent;
public String URL;
String[] clientsByID = new String[100];
private static final Log log = LogFactory.getLog (CSApplication.class);
public boolean appStart(IScope scope) {
// initiating the handler here
log.info(”Client is connected “);
log.info(”Creating Shared Objects “);
createSharedObject(scope, “adminStatus”, true);
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.removeAttributes();
adminStatus_so.setAttribute(”adminIsIn”, false);
createSharedObject(scope, “userList”, true);
//ISharedObject userList_so = getSharedObject(scope, “userList”);
//userList_so.setAttribute(”List”,list);
//userList_so.removeAttributes();
return true;
}
@Override
public boolean appConnect(IConnection conne, Object[] params) {
IServiceCapableConnection service = (IServiceCapableConnection)
conne;
log.info(”Client is connected ” + conne.getClient().getId() + ”
conne ” + conne);
log.info(”Setting stream id as : “+ getClients().size()); //
just a unique number
service.invoke(”setId”, new Object[]{conne.getClient().getId()},
this);
return true;
}
//@Override
public boolean appJoin(IClient client, IScope scope, String
userName, String userPwd) {
log.info(”Client joined app ” + client.getId());
IConnection conne = Red5.getConnectionLocal();
client.setAttribute(”userName”,userName);
client.setAttribute(”userPwd”,userPwd);
ISharedObject UserList = getSharedObject(scope,”UserList”);
if (client.getAttribute(userName)== “__mainPage__”){
//ISharedObject UserList = getSharedObject(scope,”UserList”);
UserList.setAttribute(client.getId(),userName);
}
else if(userName == adminUserName){
if(userPwd == adminUserPassword){
String IDofClient = conne.getClient ().getId();
removeFromList(IDofClient);
//URL notifications
URLNotify(IDofClient,URL);
//<- Find the Notification way
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.setAttribute(”adminIsIn”, true);
this.userName = userName;
}
rejectClient(conne.getClient());
}
return true;
}
public void putMeInLine(String userID, String userName) {
log.info(”putMeInLine:”+userID+”,”+userName);
//ISharedObject UserList_so = getSharedObject(scope,”UserList”);
clientsByID[1]= userID;
addToLine(userID, userName);
}
public String URLNotify(String clientID,String URL){
// write a Iterator to find the specied userId and then send him the URL
return URL;
}
public void addToLine(String userID,String userName){
ISharedObject UserList_so = getSharedObject(scope,”UserList”);
UserList_so.setAttribute(userID,userName);
}
public void removeMeFromLine(String userId){
ISharedObject UserList_so = getSharedObject(scope,”UserList”);
UserList_so.removeAttribute(userId);
}
public boolean removeFromList(String ID)
{
log.info(”removeFromList:”+ID);
ISharedObject userList_so = getSharedObject(scope, “userList”);
//list = userList_so.getAttributes(”list”);
Object[]list = new Object[100];
//list = userList_so.getData(ID);
for (int i=0; i<list.length; i++) {
list[i] = userList_so.getAttribute(ID);
}
if (userList_so.hasAttribute(ID)){
for (int i=0; i<list.length; i++) {
if (list[i] == userList_so.getAttribute(ID)) {
this.removeAttribute(ID);
}
}
return true;
}return false;
}
public String setName(String name){
log.info(”setName:”+name);
userName= name;
return “ack”;
}
public String setDomainName(String name) {
log.info(”setDomainName:”+name);
ISharedObject userList_so = getSharedObject(scope, “userList”);
userList_so.setAttribute(”userdomainname”,name);
return “ack”;
}
public boolean userBell(String userId){
IConnection current = Red5.getConnectionLocal();
Iterator<IConnection> itr = scope.getConnections();
while ( itr.hasNext()) {
IConnection conne = itr.next();
IServiceCapableConnection service = (IServiceCapableConnection)
conne;
if (conne.equals(current))
service.invoke(”userBell”);
}
return true;
}
public void streamPublishStart(IBroadcastStream stream) {
// Notify all the clients that the stream had been started
log.debug(”Starting the Stream Broadcast: “+stream.getPublishedName());
IConnection current = Red5.getConnectionLocal();
Iterator<IConnection> itr = scope.getConnections();
while (itr.hasNext()) {
IConnection conne = itr.next();
if (conne.equals (current))
// Current client Should not be Notified
continue;
if (conne instanceof IServiceCapableConnection) {
((IServiceCapableConnection) conne).invoke(”newStream”, new
Object[]{stream.getPublishedName()}, this);
log.debug(”Now sending notification to “+conne);
}
}
}
public void streamBroadcastStart(IBroadcastStream stream) {
}
public void streamBroadcastClose(IBroadcastStream stream) {
}
public void streamSubscriberStart(ISubscriberStream stream) {
}
public void streamPlaylistItemStop(IPlaylistSubscriberStream stream,
IPlayItem item) {
}
public void streamPlaylistItemPlay(IPlaylistSubscriberStream stream,
IPlayItem item, boolean isLive) {
}
public void streamPlaylistVODItemPause(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {
}
public void streamPlaylistVODItemResume(IPlaylistSubscriberStream
stream, IPlayItem item, int position) {
}
public void streamPlaylistVODItemSeek(IPlaylistSubscriberStream stream,
IPlayItem item, int position) {
}
public void streamSubscriberClose(ISubscriberStream stream) {
}
/**
* Get streams. called from client
*
* @return iterator of broadcast stream names
*/
public List<String> getStreams(){
IConnection conne = Red5.getConnectionLocal();
return getBroadcastStreamNames(conne.getScope());
}
/**
* Handle callback from service call.
*/
public void resultReceived(IPendingServiceCall call) {
log.info(”Received result ” + call.getResult() + ” for ” +
call.getServiceMethodName());
}
public void appDisconnect(IConnection conne,IBroadcastStream
stream,IScope scope) {
log.info(”Application is disconnected “);
IClient client = conne.getClient();
if (client.equals(adminUserName)&& scope == conne.getScope()){
ISharedObject adminStatus_so = getSharedObject(scope,
“adminStatus”);
adminStatus_so.beginUpdate();
adminStatus_so.setAttribute(”adminIsIn”, false);
stream.close();
conne.close();
super.disconnect (conne,scope);
adminStatus_so.endUpdate();
}
else
{
ISharedObject userList_so = getSharedObject(scope, “userList”);
userList_so.beginUpdate();
removeFromList( conne.getClient().getId());
stream.close();
conne.getClient().disconnect();
super.disconnect(conne,scope);
userList_so.endUpdate();
}
}
}
发表评论
-
red5检测流量
2010-07-16 17:27 1333@Override public void strea ... -
red5+hibernate
2010-07-16 17:18 1396Application 代码: package conjs.i ... -
使用Red5 录制视频
2010-07-16 17:17 4648import java.io.File; import or ... -
Red5实现直播
2010-07-16 17:14 9870发布端(Publish): var nc:NetConnect ... -
Red5 Client 调用 Red5 Server
2010-07-16 17:02 2913package com.conjs; import org. ... -
jave
2010-07-14 10:56 1317JAVE (Java Audio Video Encoder) ... -
nutch+solr
2010-07-13 17:52 1593两年前集成Nutch 和Solr 这两个Apache Luc ... -
ActiveMQ
2010-07-13 17:44 46261. 背景 ... -
red5的一些概念
2010-07-09 10:52 1292IConnection 是连接的意思 并且有getClient ... -
red5的eclipse插件地址
2010-07-09 10:05 1171Name: Red5Plugin 0.2.x (Eclipse ... -
uuid
2010-07-06 17:55 1077java uuid生成方法 UUID(Universally ... -
Java集合排序及java集合类详解:集合框架中常用类比较
2010-07-01 14:06 1979用 “ 集合框架 ” 设计软件时,记住该框架四个 ... -
Java集合排序及java集合类详解:Set
2010-07-01 14:04 14821.5 Set 1.5.1 概述 ... -
Java集合排序及java集合类详解:Map
2010-07-01 14:02 21601.4 Map 1.4.1 概 ... -
Java集合排序及java集合类详解:Collection
2010-07-01 13:50 21441.2 Collection ... -
Java集合排序及java集合类详解:集合框架概述
2010-07-01 13:47 12911.1 集 ... -
关于 Java Collections API 您不知道的 5 件事,第 2 部分
2010-06-29 13:57 677java.util 中的 Collection ... -
关于 Java Collections API 您不知道的 5 件事,第 1 部分
2010-06-29 13:55 799对于很多 Java 开发人员 ... -
关于 Java 对象序列化您不知道的 5 件事
2010-06-29 11:59 863数年前,当和一个软件团队一起用 Java 语言编写一个应用程序 ... -
使用 Apache MINA 开发高性能网络应用程序
2010-06-29 11:41 900本文将通过一个简单的问候程序 HelloServer 来介绍 ...
相关推荐
Red5是一个用Java语言编写的开源Flash RTMP服务器,支持视频、音频流、录制客户端流、共享对象、发布直播流、远程调用等特点。Red5的开发团队成员包括Chris Allen、John Grden、Dominick Accattato、Steven Gong、...
Red5是基于Java开发的,能够实现与Adobe的FMS(Flash Media Server)相似的功能,包括实时流媒体传输、录制播放视频、共享对象以及远程调用等。通过Red5,开发者可以构建诸如视频播放网站、远程教育平台、视频会议...
3. **共享对象**:Red5提供了在客户端之间共享数据的能力,这在实现多人协作游戏或实时互动应用时非常关键。 4. **屏幕共享**:通过Red5,用户可以实现桌面或应用程序的屏幕共享,这对于远程教育、在线会议等场景...
Red5是一个开源的Java编写的Flash流媒体服务器,支持将视频/音频文件转化为流媒体播放格式(如FLV和MP3),录制客户端播放流(仅限FLV格式),共享对象,现场直播流发布以及远程调用(AMF)。Red5的技术特点和应用...
包括音频、视频的发布、播放,以及数据对象的共享。 3. **录制与回放功能**:Red5支持对流媒体内容进行录制和回放,这对于在线教育、会议记录等场景十分有用。录制功能可以将实时流保存为FLV或F4V文件,而回放则能...
3. **共享对象**:Red5支持Flash客户端和服务器之间的数据共享,这在多人协作游戏或者聊天室等场景中非常有用。 4. **代理服务**:Red5可以作为FMS的替代品,如果你已经有一个基于FMS的应用,无需修改代码就能迁移...
3. **共享对象**:支持客户端间共享数据。 4. **现场直播流发布**:支持现场直播流的发布。 5. **远程调用**:实现客户端与服务器端之间的远程过程调用。 这些特性使得Red5成为即时通信、远程教育、流媒体开发、...
2. **对象共享**:在Flex和Java之间,可以通过Red5的共享对象功能进行数据共享。共享对象可以在服务器端和多个客户端之间实时同步,实现数据的即时更新。 3. **直播与点播**:Red5支持视频直播和点播服务,Flex...
Red5是一个开源的流媒体服务器平台,它提供了与Macromedia公司的Flash Media Server(FMS)相似的功能,主要支持基于Adobe Flash平台的实时通信应用,如音频、视频流,以及共享对象通信等。Red5利用Java语言开发,...
Red5是一款基于Java开发的开源流媒体服务器,它支持多种功能,包括将音频(MP3)和视频(FLV)转换为播放流,客户端播放流的录制(仅限FLV),共享对象,现场直播流发布,以及远程调用。Red5依赖RSTP作为流媒体传输...
3. **互动性**:Red5支持Flash Player的交互功能,如共享对象、远程调用和屏幕共享,这使得开发具有高度交互性的在线应用成为可能。 4. **可扩展性**:通过Java平台,Red5提供了丰富的API和插件机制,用户可以根据...
在这个例子中,我们监听了名为"chat"的流,并通过`conn.getSharedObject`获取到了共享对象,这个共享对象可以用来存储和广播聊天消息。 此外,聊天应用可能还需要处理用户注册、身份验证、私聊、群聊等功能,这就...
Red5支持RTMP协议,与FMS完全兼容,能够流化FLV和MP3文件,实现客户端流的实时录制为FLV文件,共享对象,实时视频播放以及Remoting功能。这意味着,使用Red5替换FMS时,客户端代码无需修改即可继续正常工作。 安装...
1. Red5 介绍 Red5是一个采用Java 开发开源免费的的Flash 流媒体服务器,功能和Adobe 的fms(F lash Media Server)相同,它支持把音频...共享对象;现场直播流发布;远程调用。Red5使用RSTP 作为 流媒体传输协议。
3. **对象共享(可分组共享)**: 实现了多用户间的实时数据交换,可以按照不同的群组进行管理。 4. **流媒体实时发布**: 支持即时直播功能,用户可以实现实时的音视频广播。 5. **远程方法调用**: 提供了一种机制,...