UDP Client Event - OnOffline

The event is raised when the connected server is preparing to go offline. The client is recommended to terminate the current connection and re-establish a new connection when this event is raised.

 

udp.OnOffline += OnUdpOffline;
udp.OnDisconnect += OnUdpDisconnect;

private void OnUdpOffline()
{
  // We set a flag, so we can perform re-connection in OnDisconnect event listener
  reconnectFlag = true;
  // This is raise OnDisconnect event
  udp.Disconnect();
}
// bool reconnecting is set to true when you use udp.Reconnect()
private void OnUdpDisconnect(bool reconnecting)
{
  if (reconnectFlag)
  {
    // Call the application server to indirectly obtain a new endpoint here
    // Assuming we have the new endpoint, we proceed with reconnect
    udp.SetEncryptionKeys(newSid, newKey, newIv, newMacKey);
    udp.Connect(newAddr, newPort);
  }
}