1

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?

Dave New
  • 38,496
  • 59
  • 215
  • 394

3 Answers3

1

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.

Gio
  • 1,954
  • 3
  • 22
  • 42
  • So multiple NET_STATUS event could be fired during one NetConnection.connect() call? – Dave New Jul 12 '13 at 07:41
  • 1
    `connect()` call fires 1 event with an array of possible `info` properties, but even after connection your `NetConnection` object can fire `NET_STATUS` events for `AppShutdown`, `Close`, `NetworkChange` or some of other stuff that's going on with the connection. So you should definitely leave a listener untouched until `NetConnection` is closed. – Gio Jul 12 '13 at 07:44
  • Ok thanks! My `Connect()` function above might be called regularly. If I take out the `removeEventListener`, it would start to trigger multiple anon functions. I cannot handle this event in my constructor either, because I need the callback passed into `Connect()`. Any suggestions? – Dave New Jul 12 '13 at 08:13
  • 1
    I think you've already handled that by checking the `isConnected()` method of yours, but I don't know why don't you use the `connected` property of the `NetConnection` class instead. Another thing you can do is add the `removeEventListener` just before the `addEventListener` and name your anonymous function (to make it removeable from outside). Note that `removeEventListener` won't throw an error even if your `NetConnection` object doesn't have a listener. – Gio Jul 12 '13 at 08:19
  • The connection regularly drops, so the IsConnected() check won't prevent multiple anon functions from being added to the listener. I could try the removing before adding. Otherwise I could keep to my above code, but include a second listener in the constructor to pick up straddling NET_STATUS events. This will basically do nothing (maybe just a log entry). Thanks for your replies – Dave New Jul 12 '13 at 08:24
1

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
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
  • Thanks for the answer. We are using Red5 0.9.1 (sorry, I should have specified that in my question). I believe bandwidth detection is only from version 1 onward? – Dave New Jul 14 '13 at 13:32
  • 1
    In the case of 0.9, you probably just need to add onBWDone – Paul Gregoire Jul 14 '13 at 18:05
1

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.

bond
  • 1,054
  • 8
  • 15