Following up my post last week on creating channel definitions, I realize I forgot to add one key piece of code – timeouts!

Why are these important?

For starters, the connection timeout prevents you from waiting until the end of time to get a response from the remote destination. Since you typically connect when your application first loads, this can result in an unnaturally long startup time when the remote destination is slow or unavailable.

Not having a connection timeout also causes failover (e.g. from RTMP to polling) to take a really long time.

Similarly, the request timeout helps prevent your application from appearing unresponsive. Better to handle slow asychronous calls with progress indicators rather than simply hope they’ll return in a reasonable amount of time.

So without further ado, here are the lines to add to your channel definitions for connection and request timeouts:

// sets the connection and request timeouts
var connectTimeoutInSec : Number = 3;
var requestTimeoutInSec : Number = 10;

rtmpChannel.connectTimeout = connectTimeoutInSec;
rtmpChannel.requestTimeout = requestTimeoutInSec;

pollingChannel.connectTimeout = connectTimeoutInSec;
pollingChannel.requestTimeout = requestTimeoutInSec;

The actual values are arbitrary, so you should adjust them as needed.

Original post: Creating FDS Channel Definitions in AS3