connect-to-notify-server
public void Connect(bool reconnection = true, long reconnectionDelay = 1000, long reconnectionDelayMax = 5000, int reconnectionAttempts = 1000);
Description
Connects to the real-time notification server. You can connect even if it is not activated in BACKND Console, but in this case, you will not receive any notifications.
After connecting, the authentication process starts, and the result will be passed to the OnAuthorize
handler.
Unlike the existing BACKND Base methods, you get the returned value at the handler.
Parameters
Value | Type | Description | Default |
---|---|---|---|
reconnection | bool | Whether to reconnect after disconnection | |
reconnectionDelay | long | The reconnection delay after disconnection(ms) | |
reconnectionDelayMax | long | The maximum reconnection delay after disconnection(ms) | |
reconnectionAttempts | long | The maximum number of attempts to reconnect |
Example
// Define the handler to be called upon connection
Backend.Notification.OnAuthorize = (bool Result, string Reason) => {
Debug.Log("Success/failure of connection to real-time server : " + Result);
Debug.Log("Reason when failed : " + Reason);
};
// Connect to the real-time notification server
Backend.Notification.Connect();
OnAuthorize
public OnNotificationAuthorize OnAuthorize;
Parameters
Value | Type | Description |
---|---|---|
Result | bool | Connection result(true means success and false means failure) |
Reason | string | Reason for failure('successed w/ {socket.id} ' is printed when successful) |
Description
When Connect is called, the authentication process automatically starts, and the result will be passed to the OnAuthorize handler.
Example
Backend.Notification.OnAuthorize = (bool Result, string Reason) => {
Debug.Log("Trying to connect to the real-time notification server!");
//Process after connection
if(Result)
{
Debug.Log("Successfully connected to the real-time notification server!");
}
else
{
Debug.Log("Failed to connect to the real-time notification server : Reason: " + Reason);
}
}
ResponseCase
Success cases
Result(bool) | Reason(string) | Description |
---|---|---|
true | successed w/ `$socket.id` | ErrorCode |
Fail cases
Result(bool) | Reason(string) | Description |
---|---|---|
false | bad clientAppId | ErrorCode |
bad accessToken | ErrorCode | |
bad expired accessToken | ErrorCode |