Flash Media Server 起步(7)与server端交互

这是目前为止最难的了吧~~
[url=http://www.nshen.net/blog/attachments/200602/25_152648_csc.rar]
[img]/uploads/allimg/080404/0954330.gif[/img]
要直接看原文件的点这里:[/url]
整理后就几行代码不过多解释
[1b]客户端呼叫服务器[/1b]
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
  
  }
[1b]服务器端呼叫客户端[/1b]
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));
};
[最后编辑于 N神, at 2006-02-25 15:27:21]
本文转自:http://www.5uflash.com/flashjiaocheng/Fmsjiaocheng/2280.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值