UpdateMode in DataSet Protocol

sgcWebSockets Dataset Subprotocol allows to broadcast database changes to all client connected. From sgcWebSockets 4.3.8 this protocol allows 2 update modes:

1. Replicate Table: protocol updates dataset clients when a dataset has changed.

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

Replicate Table 

This mode tries to solve a common scenario where a table is replicated for all connected clients, example, if you have a server with a stock quotes table, you want broadcast stock changes to all clients, but you don't want that a client can connect to your database. So, every time there is a change in any stock quotes, the record information will be broadcasted to all connected clients. Every client will read the record and update his own table.

You can check in Demos folder, SQLLite/MultipleDatabase demo.

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 

This mode tries to solve an scenario where server and clients share a single database (server and clients are connected to the same physical database) and clients want to be notified every time other client has done any change on a dataset.

You can check in Demos folder, SQLLite/SingleDatabase demo.

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 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; 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

RPC Progressive Results
WebSockets Client Delphi and CBuilder

Related Posts