Click or drag to resize

ExtensionRequest Class

Sends a command to the server-side Extension attached to the Zone or to a Room.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsExtensionRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.7.12.0 (1.7.12)
Syntax
C#
public class ExtensionRequest : BaseRequest
Constructors
  NameDescription
Public methodExtensionRequest(String, ISFSObject)
See ExtensionRequest(string, ISFSObject, Room, bool) constructor.
Public methodExtensionRequest(String, ISFSObject, Room)
See ExtensionRequest(string, ISFSObject, Room, bool) constructor.
Public methodExtensionRequest(String, ISFSObject, Room, Boolean)
Creates a new ExtensionRequest instance.
Top
Remarks
This request is used to send custom commands from the client to a server-side Extension, be it a Zone-level or Room-level Extension. Viceversa, the EXTENSION_RESPONSE event is used by the server to send Extension commands/responses to the client.

Read the SmartFoxServer 2X documentation about server-side Extension for more informations.

The ExtensionRequest request can be sent using the UDP protocol too: this allows sending fast stream of packets to the server in real-time type games, typically for position/transformation updates, etc.

Examples
The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the EXTENSION_RESPONSE event listener (the same command name is used in both the request and the response):
void SomeMethod() {
    sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

    // Send two integers to the Zone extension and get their sum in return
    ISFSObject params = SFSObject.NewInstance();
    params.PutInt("n1", 26);
    params.PutInt("n2", 16);

    sfs.Send( new ExtensionRequest("add", params) );
}

void OnExtensionResponse(BaseEvent evt) {
    String cmd = (String)evt.Params["cmd"];
    if (cmd == "add") {
        ISFSObject responseParams = (SFSObject)evt.Params["params"];

        // We expect an int parameter called "sum"
        Console.WriteLine("The sum is: " + responseParams.GetInt("sum"));                       // .Net / Unity
        System.Diagnostics.Debug.WriteLine("The sum is: " + responseParams.GetInt("sum"));      // UWP
    }
}
See Also