UpdateMode w protokole DataSet

· Funkcje

Podprotokół Dataset sgcWebSockets umożliwia rozsyłanie zmian bazy danych do wszystkich podłączonych klientów. Od sgcWebSockets 4.3.8 protokół ten obsługuje 2 tryby aktualizacji:

1. Replicate Table: protokół aktualizuje klientów datasetu po zmianie datasetu.

2. Notify Updates: protocol notifies clients when a dataset has changed. 

Replicate Table 

Ten tryb rozwiązuje typowy scenariusz, w którym tabela jest replikowana dla wszystkich podłączonych klientów. Na przykład: jeśli masz serwer z tabelą notowań giełdowych i chcesz rozsyłać zmiany kursów do wszystkich klientów, nie dając im bezpośredniego dostępu do bazy danych. Za każdym razem, gdy nastąpi zmiana w notowaniach, informacja o rekordzie zostanie rozsiana do wszystkich podłączonych klientów. Każdy klient odczyta rekord i zaktualizuje swoją własną tabelę.

Możesz sprawdzić to w folderze Demos, demo SQLLite/MultipleDatabase.

Configure Dataset Server

Create a new Dataset Protocol Server and configure using the following properties

oServer := TsgcWebSocketServer.Create(nil);
oProtocolDataset := TsgcWSPServer_Dataset.Create(nil);
oProtocolDataset.Server := oServer;
oProtocolDataset.Dataset := <...your dataset..>;
oProtocolDataset.ApplyUpdates := true;
oProtocolDataset.AutoSynchronize := true;
oProtocolDataset.NotifyUpdates := true;
oProtocolDataset.UpdateMode := upWhereAll;
oServer.Port := 80;
oServer.Active := true; 

 Configure Dataset Client

Create a new Dataset Protocol Client and configure using the following properties

oClient := TsgcWebSocketClient.Create(nil);
oProtocolDataset := TsgcWSPClient_Dataset.Create(nil);
oProtocolDataset.Client := oClient;
oProtocolDataset.Dataset := <...your dataset..>;
oProtocolDataset.ApplyUpdates := true;
oProtocolDataset.AutoSubscribe := true;
oProtocolDataset.NotifyUpdates := true;
oProtocolDataset.UpdateMode := upWhereAll;
oClient.Host := '127.0.0.1';
oClient.Port := 80;
oClient.Active := true; 

Notify Updates 

Ten tryb rozwiązuje scenariusz, w którym serwer i klienci współdzielą jedną bazę danych (serwer i klienci są połączeni z tą samą fizyczną bazą danych), a klienci chcą być powiadamiani za każdym razem, gdy inny klient dokona zmiany w datasecie.

Możesz sprawdzić to w folderze Demos, demo SQLLite/SingleDatabase.

Configure Dataset Server

Create a new Dataset Protocol Server and configure using the following properties

oServer := TsgcWebSocketServer.Create(nil);
oProtocolDataset := TsgcWSPServer_Dataset.Create(nil);
oProtocolDataset.Server := oServer;
oProtocolDataset.Dataset := <...your dataset..>;
oProtocolDataset.ApplyUpdates := true;
oProtocolDataset.AutoSynchronize := false;
oProtocolDataset.NotifyUpdates := true;
oProtocolDataset.UpdateMode := upRefreshAll;
>oServer.Port := 80;
oServer.Active := true; 

Configure Dataset Client

Create a new Dataset Protocol Client and configure using the following properties

oClient := TsgcWebSocketClient.Create(nil);
oProtocolDataset := TsgcWSPClient_Dataset.Create(nil);
oProtocolDataset.Client := oClient;
oProtocolDataset.Dataset := <...your dataset..>;
oProtocolDataset.ApplyUpdates := true;
oProtocolDataset.AutoSubscribe := true;
oProtocolDataset.NotifyUpdates := true;
oProtocolDataset.UpdateMode := upRefreshAll;
oClient.Host := '127.0.0.1';
oClient.Port := 80;
oClient.Active := true;