Packagecom.smartfoxserver.v2.requests
Classpublic class ExtensionRequest
InheritanceExtensionRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Sends a command to the server-side Extension attached to the Zone or to a Room.

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 extensionResponse 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, provided it is available (see the SmartFox.udpAvailable property): this allows sending fast stream of packets to the server in real-time type games, typically for position/transformation updates, etc.

View the examples

See also

extensionResponse event
SmartFox.udpAvailable


Public Methods
 MethodDefined By
  
ExtensionRequest(extCmd:String, params:ISFSObject = null, room:Room = null, useUDP:Boolean = false)
Creates a new ExtensionRequest instance.
ExtensionRequest
Constructor Detail
ExtensionRequest()Constructor
public function ExtensionRequest(extCmd:String, params:ISFSObject = null, room:Room = null, useUDP:Boolean = false)

Creates a new ExtensionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters
extCmd:String — The name of the command which identifies an action that should be executed by the server-side Extension.
 
params:ISFSObject (default = null) — An instance of SFSObject containing custom data to be sent to the Extension. Can be null if no data needs to be sent.
 
room:Room (default = null) — If null, the specified command is sent to the current Zone server-side Extension; if not null, the command is sent to the server-side Extension attached to the passed Room.
 
useUDP:Boolean (default = false) — If true, the UDP protocol is used to send the request to the server (check the SmartFox.udpAvailable property for more informations).

See also

Examples
The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the extensionResponse listener (the same command name is used in both the request and the response):
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse);
         
         // Send two integers to the Zone extension and get their sum in return
         var params:ISFSObject = new SFSObject();
         params.putInt("n1", 26);
         params.putInt("n2", 16);
         
         sfs.send(new ExtensionRequest("add", params));
     }
     
     private function onExtensionResponse(evt:SFSEvent):void
     {
         if (evt.params.cmd == "add")
         {
             var responseParams:ISFSObject = evt.params.params as SFSObject;
             
             // We expect an int parameter called "sum"
             trace("The sum is: " + responseParams.getInt("sum"));
         }
     }