Diarkis server cluster has a mechanism to handle server autoscaling.
When the cluster needs to scale in, some servers in the cluster prepares to remove themselves from the cluster.
The servers will raise the OnOffline event on the clients connected to those servers. The clients then need to re-connect.
The example below explains how to implement re-connection:
UDP Client
// This event is raised when the connected server is getting ready to remove itself from the server cluster
udp.OnOffline += HandleDiarkisOnOffline;
// This event is raised when the client connects to the server
udp.OnConnect += HandleDiarkisOnConnect;
private void HandleDiarkisOnOffline()
{
if (isInGame)
{
// If we are in game, we queue the action instead
queueOutGameActions.Add(() =>
{
//re-connect
udp.Migrate();
});
return;
}
// re-connect and raise OnConnect
udp.Migrate();
}
private void HandleDiarkisOnConnect(bool reconnected)
{
// Connected to the server
}
TCP Client
// This event is raised when the connected server is getting ready to remove itself from the server cluster
tcp.OnOffline += HandleDiarkisOnOffline;
// This event is raised when the client connects to the server
tcp.OnConnect += HandleDiarkisOnConnect;
private void HandleDiarkisOnOffline()
{
if (isInGame)
{
// If we are in game, we queue the action instead
queueOutGameActions.Add(() =>
{
//re-connect
tcp.Migrate();
});
return;
}
// re-connect and raise OnConnect
udp.Migrate();
}
private void HandleDiarkisOnConnect(bool reconnected)
{
// Connected to the server
}
C# Client SDK v0.1.12 and later.