`
hgfghwq18
  • 浏览: 45957 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

阅读更多

这是目前为止最难的了吧~~
[url=http://www.nshen.net/blog/attachments/200602/25_152648_csc.rar]

要直接看原文件的点这里:[/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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics