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
- ApplyUpdates: set to True, every time there is a change, this will be broadcasted to clients
- AutoSynchronize: set to True, every time a new client connects to server, server will send all records (metadata and data), so client will get latest information from server.
- UpdateMode: set to upWhereAll or upWhereChanged. The difference is the first send all fields of a record and second only fields changed in a update.
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
- ApplyUpdates: set to True, every time there is a change, this will be sent to server.
- AutoSubscribe: set to True, every time a new client connects to server, client subscribe automatically to update, delete and new record.
- UpdateMode: set to upWhereAll or upWhereChanged. The difference is the first send all fields of a record and second only fields changed in a update.
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 ServerCreate a new Dataset Protocol Server and configure using the following properties
- ApplyUpdates: set to True, every time there is a change, this will be broadcasted to clients
- AutoSynchronize: set to False, here is not needed to set to true, because client is connected to the same database than server.
- UpdateMode: set to upRefreshAll.
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
- ApplyUpdates: set to True, every time there is a change, this will be sent to server.
- AutoSubscribe: set to True, every time a new client connects to server, client subscribe automatically to update, delete and new record.
- UpdateMode: set to upRefreshAll.
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;