目前我正在使用flex和FMS(Flash Media Server)进行客户端和服务器端通信
我正在尝试执行以下程序,该程序每2秒检查一次连接状态,如果客户没有响应,则断开连接。
我在这里得到一个错误:
ReferenceError:错误#1069:在flash.net.NetConnection上找不到属性ping,并且没有默认值。
客户端代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import flash.net.NetConnection;
public var nc:NetConnection;
public var res:Responder;
public function netconn():void
{
nc = new NetConnection();
nc.connect("rtmp://127.0.0.1/ChkConn",user.text);
nc.addEventListener(NetStatusEvent.NET_STATUS, handle);
}
public function handle(event:NetStatusEvent):void
{
switch(event.info.code)
{
case "NetConnection.Connect.Success":
status.text="Connected";
break;
case "NetConnection.Connect.Failed":
status.text="Failed";
break;
case "NetConnection.Connect.Rejected":
status.text="Rejected";
break;
case "NetConnection.Connect.Disconnect":
trace("coming");
status.text="Close";
break;
}
}
public function pings():void
{
trace("a ping call from the server has been received");
}
public function disconn():void
{
nc.close();
nc.addEventListener(NetStatusEvent.NET_STATUS, handle);
status.text="Disconnected";
}
]]>
</mx:Script>
<mx:Panel x="224" y="41" width="348" height="118" layout="absolute">
<mx:TextInput x="84" y="24" id="user"/>
<mx:Button x="253" y="24" label="Connect" click="netconn()"/>
<mx:Text x="10" y="26" text="Username"/>
</mx:Panel>
<mx:Text x="235" y="207" text="Status:"/>
<mx:Text x="295" y="207" text="Disconnected" id="status"/>
<mx:Button x="295" y="263" label="Disconnect" click="disconn()"/>
服务器端代码
// ActionScript Communications Document
application.onAppStart=function()
{
trace("Application Start");
};
application.onConnect=function(client,name)
{
anyvariable=name;
monitorConnection(client);
if(name!="user1")
{
application.rejectConnection(client);
trace(name+" Rejected");
}
else
{
application.acceptConnection(client);
trace(name+" Connect");
}
};
clientPingResponder = function(client) {
this.onResult = function(res) {
trace("ClientPingResponder.onResult Received: " + res);
clearInterval(client.cleanupTaskId);
}
this.onStatus = function(info) {
trace("ClientPingResponder.onStatus Received: " + info);
}
};
monitorConnection = function(client) {
client.isAlive = function() {
trace("client.isAlive has been fired");
client.cleanupTaskId = setInterval(client.dead, 2 * 1000);
client.call("pings", new clientPingResponder(client));
}
client.dead = function() {
trace("cleanupTaskId: " + client.cleanupTaskId);
trace("monitorTaskId: " + client.monitorTaskId);
clearInterval(client.cleanupTaskId);
clearInterval(client.monitorTaskId);
trace("ghost connection has been detected");
application.disconnect(client);
}
client.monitorTaskId = setInterval(client.isAlive, 7*1000);
trace("detected");
}
application.onDisconnect=function(client)
{
//application.disconnect(client);
trace(anyvariable +" Disconnect");
};
任何帮助都是Appriciated。谢谢
答案 0 :(得分:1)
你需要类似的东西。
nc.client = this;