编辑: 麒麟兔爷 2019-07-04

8 理服务器调用客户端方法有返回值就就必须实现 IPendingServiceCallback 接口,并调用方式 改为sc.invoke( clientMethod , new Object[]{ One , 1},this);

this 是任意一个实现IPendingServiceCallback 接口的类,在接口的 resultReceived 方法中处理返回值.现在把上面 的类改成下面样子 package first;

im port org.red5.server.adapter.Applic ationAdapter;

im port org.red5.server.api.IConnection;

im port org.red5.server.api.service.IPendingServiceCall;

im port org.red5.server.api.service.IPendingServiceCallback;

im port org.red5.server.api.service.IServiceCapableConnection;

public class Application extends ApplicationAdapter im plements IPendingServiceCallback{ @Override public boolean appConnect(IConnection arg0, Object[] arg1) { callClient(arg0);

return true;

} private void callClient(IConnection conn){ if (conn instanceof IServiceCapableConnection) { IServiceCapableConnection sc = (IServiceCapableConnection) conn;

sc.invoke( clientMethod , new Object[]{ One , 1},this);

} } public void resultReceived(IPendingServiceCall arg0) { System .out.println( 来自客户端到返回: +arg0.getResult());

} } 把客户端的 private function clientMethod(str:String,num :Number):void{ Alert.show( 接收 +str+(num+1));

} 改成 private function clientMethod(str:String,num :Number):String{ Alert.show( 接收 +str+(num+1));

Return 客户端返回来的字符串 ;

} 测试可以从 red5 的框里看到输出 客户端返回来的字符串 3.遍历所有连接到服务器端的用户 遍历所有链接到服务器的客户端是常常的事,如好友上线,则要及时把这个消息通知给 在线的人员. Red5 通过IConnection.getscope()得到所在 scope, 通过scope 可以得到连接到这个 scope 的所有客户的连接.在得到连接后就可以通过连接调用客户端方法.如调用每个客户端的 clientMethod 方法一遍可以把服务器改成下面的样子 package chapter2;

im port java.util.Iterator;

作者:周英科 email:li_li_li87222@163.com.qq:543246541

9 im port org.red5.server.adapter.Applic ationAdapter;

im port org.red5.server.api.IConnection;

im port org.red5.server.api.IScope;

im port org.red5.server.api.service.IPendingServiceCall;

im port org.red5.server.api.service.IPendingServiceCallback;

im port org.red5.server.api.service.IServiceCapableConnection;

public class Application extends ApplicationAdapter im plements IPendingServiceCallback{ @Override public boolean appConnect(IConnection arg0, Object[] arg1) { this.callEvery(arg0.getScope());

return true;

........

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题