Class ExtensionRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class ExtensionRequest
    extends 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.

    Example
    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 void someMethod() {
         sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 if (evt.getArguments().get("cmd") == "add") {
                     ISFSObject responseParams = (SFSObject)evt.getArguments().get("params");
                     
                     // We expect an int parameter called "sum"
                     System.out.println("The sum is: " + responseParams.getInt("sum"));
                 }
             }
         });
         
         // Send two integers to the Zone extension and get their sum in return
         ISFSObject params = new SFSObject();
         params.putInt("n1", 26);
         params.putInt("n2", 16);
         
         sfs.send(new ExtensionRequest("add", params));
     }
     
    See Also:
    SFSEvent.EXTENSION_RESPONSE
    • Field Detail

      • KEY_CMD

        public static final java.lang.String KEY_CMD
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_PARAMS

        public static final java.lang.String KEY_PARAMS
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_ROOM

        public static final java.lang.String KEY_ROOM
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExtensionRequest

        public ExtensionRequest​(java.lang.String extCmd,
                                com.smartfoxserver.v2.entities.data.ISFSObject params,
                                Room room,
                                boolean useUDP)
        Creates a new ExtensionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        extCmd - The name of the command which identifies an action that should be executed by the server-side Extension.
        params - An instance of SFSObject containing custom data to be sent to the Extension. Can be null if no data needs to be sent.
        room - 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 - If true, the UDP protocol is used to send the request to the server (check the SmartFox.udpAvailable property for more informations).
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), SFSObject
    • Method Detail

      • getUseUDP

        public boolean getUseUDP()
        * API internal usage only *
      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *