zoukankan      html  css  js  c++  java
  • 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;
    }

    }

    关注我: weibo.com/holycy
  • 相关阅读:
    正则表达式判断手机号是否11位
    php-流程管理(发起流程和审核流程)
    php-流程管理(新建流程)(php+Ajax)
    php-人员权限管理(RBAC)
    状态压缩DP
    树形DP
    Broken Keyboard UVA 11988 数组实现链表
    Trees in a Wood UVA
    POJ1061 青蛙的约会 拓展欧几里得
    UVA10215The Largest/Smallest Box(小数精度)
  • 原文地址:https://www.cnblogs.com/holycy/p/2261334.html
Copyright © 2011-2022 走看看