NetConnection class
71
Because of network and thread timing issues, it is better to place a
NetConnection.onStatus
handler in a script before a
NetConnection.connect()
method. Otherwise, the connection
might complete before the script executes the
onStatus
handler initialization. Also, all
security checks are made within the
NetConnection.connect()
method, and notifications
will be lost if the
onStatus
handler is not yet set up.
If the specified connection is already open when you call this method, an implicit
NetConnection.close()
method is invoked, and then the connection is reopened.
During the connection process, any server responses to subsequent
NetConnection.call()
,
NetStream.send()
, or
SharedObject.send()
methods are queued until the server
authenticates the connection and
NetConnection.onStatus
is invoked. The
call
or
send
methods are then processed in the order received. Any pending updates to remote shared
objects are also queued until the connection is successful, at which point they are transmitted
to the server.
Video and audio, however, are not queued during the connection process. Any video or audio
that is streaming from the server is ignored until the connection is successfully completed. For
example, confirm that the connection was successful before enabling a button that calls the
NetStream.publish()
method.
If your connection fails, make sure you have met all the requirements for connecting
successfully:
■
You are specifying the correct protocol name for connecting to the server (
rtmp
, or
rtmpt
,
for the Flash Media Server).
■
You are connecting to a valid application on the correct server.
■
You have a subdirectory in the Flash Media Server applications directory with the same
name as the application specified in the connection URL.
■
The server is running.
To distinguish among different instances of a single application, pass a value for
instanceName
as part of
targetURI
. For example, you may want to give different groups of
people access to the same application without having them interact with each other. To do so,
you can open multiple chat rooms at the same time, as shown below.
my_nc.connect("rtmp://www.myserver.com/chatApp/peopleWhoSew")
my_nc.connect("rtmp://www.myserver.com/chatApp/peopleWhoKnit")