windows-usage-guide

*We assure you that we do not spam. You may receive occasional emails from us.
 You can always unsubscribe.
Windows

C# Getting Started

WarpClient provides an interface for applications to interact with the cloud services. It allows client side applications to connect, subscribe and manage server side rooms, lobbies and users. The APIs are developed to be used asynchronously, which means you simply add the corresponding request listeners to the WarpClient instance to receive responses and updates. This page describes to how to set up your connection with the cloud server and introduces API usage.

Complete API Reference

In order to use the various functions available, you will have to initialize and connect the instance of WarpClient. WarpClient is initialized by passing the apiKey and secretKey which you received after creating an app from AppHq (App42 management console).

WarpClient.initialize("Your API Key", "Your Secret Key");

After initialization, you are ready to connect and authenticate with your application on the server. It is recommended you implement and add a connection request listener which will be called by WarpClient with the result of the connection and authentication requests.

WarpClient myGame = WarpClient.GetInstance();
myGame.AddConnectionRequestListener(new MyConnectionListener());
myGame.Connect("TestUserName");

The connection request listener callback will be invoked once the connection with the Warp server has been established. If this is successful,you can go ahead and call the authenticate API by giving in the user name with which the client wishes to join the online application. Note that two users with the same name can not be connected to the online application simultaneously. Here is a simple implementation of a request listener.

public class ConListen : com.shephertz.app42.gaming.multiplayer.client.listener.ConnectionRequestListener
    {
        public ConListen()
        {
            
        }
        public void onConnectDone(ConnectEvent eventObj)
        {
            if (eventObj.getResult() == WarpResponseResultCode.SUCCESS)
            {
                Console.WriteLine("connection success");
            }
            else
            {
                Console.WriteLine(("connection fail");
            }

        }
        public void onDisconnectDone(ConnectEvent eventObj)
        {
        }
    }

Below are the Request Result codes and their description that can be retrieved when an event callback is invoked from the event instance

byte SUCCESS = 0;    
byte AUTH_ERROR = 1;    
byte RESOURCE_NOT_FOUND = 2;    
byte RESOURCE_MOVED = 3;     
byte BAD_REQUEST = 4;
byte CONNECTION_ERR = 5;
byte UNKNOWN_ERROR = 6;

Once you have successfully connected you can either join the lobby or join a particular room. You should also subscribe the lobby or the room joined to catch the notifications generated in that particular room or lobby.

myGame.JoinRoom(roomId);
myGame.SubscribeRoom(roomID);

To exchanges messages you can either send messages in plain text format using sendChat() method or send messages in binary format using sendUpdate() method respectively. To catch the messages send through sendChat() method use the onChatReceived() method of MyNotificationListener and to catch the messages send through onUpdatePeersReceived() method of MyNotificationListener.

myGame.SendChat(message);

Appwarp also allows you to set custom data for users and rooms through the methods SetCustomUserData() and SetCustomRoomData(). To retrieve the custom data and other information WarpClient comprises GetLiveUserInfo() and GetLiveRoomInfo() methods.