rpc-appwarps2

AppWarp S2 provide support for RPC(Remote Procedure Call). AppWarp S2 provide RPC on zone and room level. To implement RPC AppWarp S2 has specific adapters to achieve RPC at zone level user has to define method in class implementing BaseZoneAdaptor and to achieve RPC in room level user has to define method in BaseRoomAdaptor or BaseTurnRoomAdapter.

Call RPC from client

To call RPC from client AppWarp S2 has different API for Zone and Room.

RPC at Zone Level

RPC method defined in class implementing BaseZoneAdapter

     /**
     * Invoked when a Zone RPC request done
     * 
     * @param functionName: name of the function which we have to call
     * @param args: number of arguements for the function
     */
    public void invokeZoneRPC(String functionName, Object...args)
              

Result

result of this API call we get in onRPCDone of the ZoneRequestListener

/**
     * Invoked in response of invokeZoneRPC
     * 
     * @param result: WarpResponseResultCode for the RPC call
     * @param function: function name for which RPC Done
     * @param returnValue: returned value by function
     */
    public void onRPCDone(byte result, String function, Object returnValue)
              

RPC at Room Level

RPC method defined in class implementing BaseRoomAdaptor or TurnBaseRoomAdaptor

/**
     * Invoked when a Room RPC request done
     * 
     * @param roomId: roomId
     * @param functionName: name of the function which we have to call
     * @param args: number of arguements for the function
     */
    public void invokeRoomRPC(String roomId, String functionName, Object...args)

Result

result of this API call we get in onRPCDone of the RoomRequestListener

/**
     * Invoked in response of invokeRoomRPC
     * 
     * @param result: WarpResponseResultCode for the RPC call
     * @param function: function name for which RPC Done
     * @param returnValue: returned value by function
     */
    public void onRPCDone(byte result, String function, Object returnValue)

Implement RPC on server

As discussed above RPC can be implemented on zone and room level. To implement user only need to define function in corresponding adapter for example in RummyDemo we have implemented room RPC to request new card to do this following method is defined in RummyRoomExtension.java

public int requestNewCard(String username){
        int newCard = getNewCard();
        ...
        return newCard;
    }

to call from client:

theClient.invokeRoomRPC(roomId, "requestNewCard", Utils.userName);

When to use room or zone rpc

It depends upon use cases for example if any data required at the time of game play e.g. RummyDemo then use Room RPC and if we need information about other rooms and users then use zone RPC e.g. You want to join room where your friends are playing so in zone you can iterate rooms and users and can match username with your friends facebook id.

Is RPC supported on all client SDKs?

RPC feature is available Android, iOS, WP, HTML5, Corona, Cocos2Dx, Unity, Marmalade, Java, .Net/Mono