RED5遍历客户端并生成在线列表[转]

RED5遍历客户端并生成在线列表
一个小小的马虎,让这段程序调试了整整半天,郁闷。。不过终于可以了:)呵呵。本程序返回的在线列表格式为:
连接ID1,连接用户名1;连接ID2,连接用户名2;…
继续写下面的程序去了,呵呵


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 java.util.*;

public class Application extends ApplicationAdapter {
private IScope appScope;
private String username="";

//取得本次连接的IScope
//appStart将在连接开始的时候自动触发,等同于FMS的onAppStart
public boolean appStart(IScope app) {
appScope = app;
return true;
}

//连接时触发的函数,定义本过程中的username,等同于FMS的onConnect
public boolean appConnect(IConnection conn, Object[] params)
{
username=(String)params[0];
return true;
}

//连接加入时触发的函数,写入username的值
public boolean appJoin(IClient client, IScope app)
{
client.setAttribute("username",username);
return true;
}

//客户端调用函数,将返回目前登陆的在线列表
public String login()
{
IConnection current = Red5.getConnectionLocal();
System.out.println("<---"+current.getClient().getId()+":"+current.getClient().getAttribute("username"));
return getOnlineList();
}

//取得在线列表,对在线的客户端进行遍历,并显示。
public String getOnlineList()
{
Iterator it=appScope.getConnections();
String onLineList=”";
while(it.hasNext())
{
IConnection this_conn=it.next();
IClient ic=this_conn.getClient();
String u=ic.getAttribute(”username”).toString();
onLineList+=ic.getId()+”,”+u+”;”;
System.out.println(u);
}
System.out.println(”—>”);
return onLineList;
}

public boolean sendMSG()
{
//IScope scope = conn.getScope();
Iterator it = appScope.getConnections();
String i=”";
while(it.hasNext())
{
IConnection this_conn=it.next();
i+=this_conn.getClient().getAttribute(”username”)+”,”;
}
return true;
}

}

posted @ 2011-11-24 10:55  holycy  阅读(345)  评论(0编辑  收藏  举报