• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>FMS>文章内容
  • Flash Media Server 起步 (7)与server端交互

  • 来源:N神AS研究所 作者:N神 2007-11-05 【

这是目前为止最难的了吧~~ 要直接看原文件的点这里:

整理后就几行代码不过多解释

客户端呼叫服务器

fla:
//客户端呼叫server端msgfromclient函数,并将返回值trace出来
mync = new NetConnection();
mync.connect("rtmp://localhost/connect");
//返回值
var resObj = new Object();
resObj.onResult = function(val):Void {
  trace("val"+val);
};
mync.call("msgfromclient", resObj, "第一个call");

服务器端代码是放在main.asc里的,你可以到你的application下的你的目录下建一个main.asc,写代码

main.asc:
//要把函数定义到Client上!!
application.onConnect = function(client) {
  /* 在这里定义也可以,在Client.prototype里定义也可以
  client.msgfromclient=function(what){
    trace(what+"进来了")

 var aa="呼叫成功并返回结果"
    return aa
    }
  */
application.acceptConnection(client);
};

Client.prototype.msgfromclient=function(what){
  trace(what+"进来了")

 var aa="呼叫成功并返回结果"
    return aa
  
  }

服务器端呼叫客户端

fla:
//server呼叫client端
//要把函数定义到nc上!!
//
mync = new NetConnection();
mync.onStatus = function(info) {
  if (info.code == "NetConnection.Connect.Success") {
    trace("连接成功");
  }
};
mync.connect("rtmp://localhost/connect");
mync.msgfromserver = function(msg) {
  trace(msg);
};

main.asc:
application.onConnect = function(client) {
application.acceptConnection(client);
client.call("msgfromserver",null,"服务器叫你啊")
};
服务器端很少要求客户端返回值,如果一定要返回,一本书上是这么写的,没细看
// Define a class that just stores the client ID.
AreYouOkResultHandler = function (clientID) {
 this.clientID = clientID;
};
// Handle the result of calling areYouOk( ).
AreYouOkResultHandler.onResult = function (val) {
 trace("Client " + this.clientID + " returned " + val);
};

application.pingClient = function (clientObj, clientID) {
 // Invoke a message on the client.
 clientObj.call("areYouOk", new AreYouOkResultHandler(clientID));
};



上一篇:Flash Media Server 起步 (6)写个简单的聊天室   下一篇:Flash Media Server 起步 (8) client与server交互进阶
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)