Wowza Community

ActionScript code to attempt to connect over rtmp and if that fails rtmpt (rollover)

https://www.wowza.com/docs/how-to-set-up-protocol-rollover-with-actionscript

There really is not any magic here. It should just work every where. What aspect is not working for you?

Charlie

I do not know of anything to look at specifically. If you have get it down to a reproducible case, then I can look at it.

Charlie

I got this rollover to work nicely on my laptop for development, using Windows XP. Thanks for the code for that.

Then I tested it on Amazon AWS EC2 (Fedora 8) and it worked there also, but it took about 15 seconds to return onStatus == Failure. Seems like a long time to ask a client to wait. Anybody know a setting on the AWS EC2 Fedora that controls that? A connect timeout setting?

I did a Google search, but got some conflicting solutions and had concerns about changing settings with the OS.

Is there a simpler Java configuration setting I overlooked?

Hi Charlie,

We implemented this into our wowza player and most of the time it works well. Unfortunately there have been some random instances of our video beginning to play and then being interupted after say 5 seconds with the error message we set to display at your “Failed to connect after “+ncTryIndex+” tries”);" point.

As mentioned it is only happening to a selection of people. We are not sure if it may be a strain on the server perhaps? That somehow sends a failed status when it has actually already connected?

We are using the code like below and replaced nc.connect(serverName) in the doConnect() function in your standard as2 player with tryConnect();

We set init() to run just before mainInit() at the bottom of the standard player.

As mentioned most of the time it works fine and it definitely switches ports if the first one is blocked. Any ideas? Thanks

var ncConnectTimer:Number = 0;

var ncConnectTimeout:Number = 8000; // 8 seconds

var ncDomain:String = “OUR IP”;

var ncProtocol:String = “rtmp”;

var ncProtocol2:String = “rtmpt”;

var ncPort:Number = 1935;

var ncPort2:Number = 80;

var ncApplication:String = “flvsecure”;

var ncTryIndex:Number = 0;

var url:String = “”;

function tryConnect()

{

clearConnectTimer();

switch(ncTryIndex)

{

case 0:

ncConnectTimeout= 8000

url = ncProtocol + “://”+ncDomain+":"+ncPort+"/"+ncApplication;

trace("tried " + url)

break;

case 1:

ncConnectTimeout= 15000

ncPort = ncPort2;

ncProtocol = ncProtocol2;

url = ncProtocol + “://”+ncDomain+":"+ncPort+"/"+ncApplication;

trace("tried " + url)

break;

default:

{trace(“Failed to connect after “+ncTryIndex+” tries”);

url = “”;

statusBox.text=“failed to connect”;

nc.close();

nc=null;

gotoAndStop(2);

}

break;

}

if (url.length > 0)

{

nc.connect(url);

ncConnectTimer = setInterval(_root, “tryReconnect”, ncConnectTimeout);

}

}

I don’t think it has anything to do with this code. It sounds like the player can’t connect to Wowza. Does it happen to same people over and over again or can it happen to any one at any time?

Charlie

I think if you put a port in your initial rtmp connection string this won’t happen, i.e., make your first attempt with something like this:

rtmp://[wowza-address]:1935/yourApp

Because Flash player 10 has a built-in protocol rollover, but it is only active if you leave off the port.

Richad

In that case, make sure the process is stopped when you get “NetConnection.Connect.Succcess” notification in your NetConnection NetStatusEvent handler.

Richard

Try adding a boolean: var isConnected:Boolean = false, then set to true on connect success, and test in tryReconnect:

function tryReconnect()
{
	trace("tryReconnect");
	clearConnectTimer();
	if (isConnected)
		return;
	ncTryIndex++;
	tryConnect();
}

Richard

I’m not sure. The only thing I can suggest is to add many trace statements to see what’s happening. (you can’t use break points because a timer is involved so you don’t want to stop the code)

Richard

The client-side of this is using a timer that is set for 3000 milliseconde (3 seconds). If the server returns “NetConnection.Connect.Failed” notification before that, a rollover happens, but otherwise 3 seconds is the interval. So check your code. Should be 3 seconds, and you can set it for less if you want.

Richard

Jake Hilton has a port tester here:

http://www.jakehilton.com/?q=node/43

You can use the one running on that page by putting your Wowza IP address and an Appname in the text boxes, and there is downloads for AS2 and Flex versions.

Richard

Flowplayer might have a plugin for this already. But if not you will have to modify Flowplayer source code. You have to set up a development environment for Flowplayer:

http://flowplayer.org/documentation/developer/development-environment.html

Then use Flex or Flash Builder menu: Search > Find in Files, and search for “.connect”

When you find where the RTMP connection happens, you can work that code in.

Richard

Flowplayer RTMP plugin can natively handle RTMP/RTMPT/RTMPE/RMPTE rollover. See plugin code here.

But there’s a weird behaviour when using RTMPE : http://flowplayer.org/forum/5/37221.

Still no fix …

Hi,

Thanks for your quick response but if I understand it correctly, I am already doing this.

i.e

var ncProtocol:String = “rtmp”;

var ncProtocol2:String = “rtmpt”;

var ncPort:Number = 1935;

var ncPort2:Number = 80;

var ncApplication:String = “flvsecure”;

var ncTryIndex:Number = 0;

url = ncProtocol + “://”+ncDomain+":"+ncPort+"/"+ncApplication;

Thanks,

Joe

For reference, I am using flash player 9 when i compile the swf…

Thanks, I have used

if(infoObj.code == “NetConnection.Connect.Success”) clearConnectTimer();

with the same clearConnectTimer function from this post, is this what you mean? When I test by closing the ports on my firewall it works ask expected and works on our live server 99% of the time. It’s just some cases that video plays for a few seconds and then brings up the error message.

Thanks,

Joe

Hi Richard, Thanks for this suggestion. I am going to try it. I should have really thought of this myself, as it is almost as though we are getting a NetConnection.Connect.Failed status after we have already got NetConnection.Connect.Success? If this is what’s happening, I have no idea why, but it makes sense that your change would solve this.

Nice one

Hi,

I am still having this problem, so this fix doesn’t seem to have sorted it.

It seems that the problem is happening in Firefox, I have not yet had a report of it happening in IE and cannot recreate it in IE.

I am using the as2 simple player example with this mod as I have detailed.

I am using the simple player in an external swf and loading it into my main swf everytime I start a new video, simply passing the file name in. Is there anything in the external swf that could be affecting it or perhaps cache of the last version of swf’s net connection info. Excuse my poor knowledge if this sounds stupid!

Thanks, this problem is really difficult to dianose as it is intermittent but I am pretty sure it is Firefox specific, unless it is Flash Player specific?

Thanks,

Joe

Thanks, one of the reasons I haven’t been able to do it this way is that it only seems to be happening on our production servers, I’m not sure if this is useful information. I have flash player debugger on IE so that I can get traces from the live swf, I’ll set this up for Firefox and see if I can see anything more. This was just my first steps incase there were any known issues with certain versions of firefox/certain versions of flash player! thanks