Question

Occasionally I'm getting an unhanded NetStatusEvent when using NetConnection to connect to a Red5 server:

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed

This is how I am connecting (the only place where NetConnection.connect() is called):

public function Connect(callBack:Function = null):void 
{
    if (IsConnected())
    {
        if (callBack != null) 
        {
            callBack.call();
        }
    }
    else // Not connected
    {
        netConnect.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void
        {
            // OnConnect called whenever there is a net status event
            OnConnect(e, callBack);
            netConnect.removeEventListener(NetStatusEvent.NET_STATUS, arguments.callee);
        });

        try
        {
            // Attempt to connect to Media Server
            netConnect.connect(MEDIA_SERVER_URI, true);
        }
        catch(error:Error)
        {
            logger.LogError("NetConnection.connect threw an exception.", error);
        }
    }
}

I am adding an event listener for NetStatusEvent.NET_STATUS. How is it possible that sometimes my listener called?

Était-ce utile?

La solution

You're removing your listener in your NetStatusEvent handler. You should keep it until the connection is closed. This is why NetStatusEvent is only handled once before its listener is removed. Any other than first event will throw that error.

So remove netConnect.removeEventListener(NetStatusEvent.NET_STATUS, arguments.callee);

NetConnection dispatches that event quite a lot, depending on what is happening. You have to handle the event until every time. For a list of possible values of the info property visit this Link. There's also a little example of how to handle the event at the end of the page.

Autres conseils

You may see this if your client does not handle the onBWCheck or onBWDone methods. This will also happen if you have bandwidth detection turned on; turn it off on the server by changing this parameter in the red5.properties file and restart the server.

rtmp.bandwidth_detection=false

Blockquote

Just an additional piece of information. Dispatching NetStatusEvent objects with info.level = "error" will always throw an Unhandled Exception. Its a special use case. I, for example, wrap all of this functionality and change the level to "info" before re-dispatching the event.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top