If you run more than a Flash Communication Server, you will need to limit the connection every application sooner or later.
Quantity, especially your program is in popular. After all, you don't want your multiuser water balloon game, because your virtual data program takes up all server connections. My prescription is to all The communication program is limited to the connection.
Let's start, see what happens when the flash file is connected to Flashcom Server. Unless otherwise pointed out, Flashcom
Server always receives the connection request sent by the client until there is no more route. If you want to change this behavior, you need to set up
Some services rules are set, when you decide whether you should allow or refuse to connect, write some server-side AS to achieve this task.
Imagine that you don't want more than 5 users to connect to your program at the same time. Create a new text in your selected text editor and save it as
Main.asc. This main.asc file allows you to add new capabilities for your communication program. Add the following code:
Application.onnect = function (pclient) {
IF (Application.Clients.Length> = 5) {
Application.rejectConnection (PCLIENT);
} else {
Application.AcceptConnection (PCLIENT);
}
}
Here will explain the progress line, what are they doing?
Application.onnect = function (pclient) {
...
}
Application.onConnect is an event that is triggered as long as a client issues a temporary connection to the server.
At this point, the server must decide whether this connection is allowed to continue or refuse to close this connection. Creating a function for this event is a simple
The way, it makes your server to perform some rules when there is this situation.
IF (Application.Clients.Length> = 5) {
Each program instance has a array called "Clients", which contains the reference to each of the received connections to the program. Check this
The group's Length property tells you the number of clients currently connected. Compares by this value and the value you choose, you can set a limit
To perform the above code. Here, you detect if more than 5 clients are connected. It is recommended that the connection request will not trigger the onConnect event.
It is formally recognized and does not count such (translator: send request) client into the clients array, even if it occupies the available connection of the server.
It is only temporary
Application.rejectConnection (PCLIENT);
This code is performed when the number of connections exceeds the limit 5. First it will send a status code via the PCLIT to give the client brief explanation,
It seems like this: "NetConnection.connect.rejected" then shut down the temporary connection immediately. Notice the status code in front, etc., will be seen.
} else {
Application.AcceptConnection (PCLIENT);
}
This code is implemented when the number of connections is 5 or less. It is just allowed to continue and relax a status code to the client:
"NetConnection.connect.Success"
These are all the code in the main.asc file. Put this file into the Flashcom sever directory of your program. Main.asc
Just quote when the program is started for the first time, so if a program instance is already running on the server, it will restart it.
At this point, you have already provided a powerful decision for the server, allowing us to provide a method to respond to the service on the client.
The decision of the device.
Write the following functions in your Flash file to operate a connection to the server. Put this function in your movie's first frame,
Be used when you use it:
Function doconnect () {
Vconn_nc = new netConnection ();
vconn_nc.connect ("RTMP: //yourflashcomser.com/yourapp"); vconn_nc.onstatus = function (pin) {
IF (Pinfo.code == "NetConnection.connect.Success") {
gotoandplay ("start");
} else if (pinfo.code == "NetConnection.connect.Failed" ||
Pinfo.code == "NetConnection.connect.reject")
{
GotoandPlay ("Access Denied");
}
}
}
Here is a progressive explanation.
Vconn_nc = new netConnection ();
vconn_nc.connect ("RTMP: //yourflashcomser.com/ourapp");