3.4. Multiple Simultaneous NetConnection Objects
Macromedia recommends against making
multiple connections from a single Flash movie to a FlashCom Server
or Servers at the same time. First of all, each server can handle
only so many simultaneous connections and the data transfer overhead
that goes with them. Furthermore, FlashCom is licensed by the number
of simultaneous connections. Therefore, whenever possible, avoid
designing communication applications that require multiple
simultaneous connections. However, a Flash movie can connect
simultaneously to different applications or different instances of
the same application; it can also connect multiple times to the same
application instance, if necessary. This is an especially useful
feature when testing applications and in developing larger scale
multi-instance applications.
The simple test script in Example 3-7 makes two
connections to the same
chat room instance.
Example 3-7. Using more than one NetConnection object
NetConnection.prototype.onStatus = function (info) {
trace(this.name + ": " + info.code);
};
nc1 = new NetConnection( );
nc1.name = "First connection";
nc2 = new NetConnection( );
nc2.name = "Second connection";
nc1.connect("rtmp:/testChat/room1", "Guest", "Guest");
nc2.connect("rtmp:/testChat/room1", "Guest", "Guest");
Assuming there are no problems with the network or server, the trace
output from this test will look like this:
First connection: NetConnection.Connect.Success
Second connection: NetConnection.Connect.Success
Multiple connections are useful when debugging, the topic of the next
section.
 |