fms 服务器与客户端交互

来源:互联网 发布:翻译英语的软件 编辑:程序博客网 时间:2024/05/22 04:50

转自:http://www.riabook.cn/blog/article.asp?id=404


客户端呼叫服务器


//客户端呼叫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);};

//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));};


原创粉丝点击