views:

367

answers:

5

I wanna build a Win32 app of Client/Server (or 3-tier) type with follow features:

  • When the "A" client does a modification (update,insert, etc) into a database, the rest of clients viewing the same record set can get almost "instantly" a fresh view of this data
  • a client can be notified when a connection to database get lost

could someone help me? Thanks in advance

Pdta: My Database is MySQL 5.1

A: 

If MySQL doesnt support somekind of pushing info or attatching clients you would need to use a middle tier running on a server. That server keeps track of connected clients. But it would probably be a heck of a job.

I know that the "bigger" edititions of Delphi has somekind of support of building this kind of client/server software.

Richard L
A: 

I know it has nothing to do with your application, but Firebird has a nice feature to do exactly this. You can read more about them here (link to a PDF).

Now, if you need to do this with MySQL and Delphi, the easiest way I can think of is doing something "AJAX LIKE" on your Win32 app. That is having a server side app (you could use a WebServer with PHP, Java, .NET or whatever you want) that will serve your requests asking for data updates. On the server side app, just do a query asking for modifications into your MySQL Database.

Hope it helps.

Pablo Santa Cruz
+2  A: 

My answer depends on your network architecture but I tend to use IP for this type of thing. Something like Multicast is an ideal way to notify all clients on the Network of an event. Simply multi-casting or broadcasting (UDP) the ID of the updated record may be all that is required. If another client is interested in the record, it can then refresh it from the Database.

The Indy Multicast Client/Server components will provide a simply way to implement this in your app.

Gerard
We used something similar (but grossly over engineered) at a previous employer. Probably just need to send a table identifier, record id and operation (add/update/delete) action.
Gerry
multi-cast will only work on your local LAN (and only if the switches forward multi-cast packets); Billiardo should use the observer pattern.
Jeroen Pluimers
A: 

If you have a three tier type application, the client communicates with the aplication server. This connection could use callbacks to the clients to notify them about important events. DataSnap supports callbacks (afaik also data change notifications).

If you build your own application server. the client could open a socket connection to the server (in a thread) and listen for event notifications. The Indy Telnet client example in Protocols/IdTelnet.pas is a good starting point to create a very simple notification implementation. It uses the TIdTelnetReadThread class to listen for the server responses to key input and protocol negotiations.

If your application needs to run in Terminal Server environments, where Ports will not be virtualized AFAIK, it is safer to connect from the client to the server (instead of opening client socket ports for peer-to-peer communication).

mjustin
+2  A: 

Note that by doing this, and having lots of clients, you will potentially get a lot of network traffic. This is exactly the reason that most client-server applications do not do this.

If you really want to do this, then the proper was is to implement the 'observer pattern'; a basic example on that design pattern in Delphi has been described by Joanna Carter in her blog.

Then you need to extend that pattern so it works over a network. So at least you need some server process that handles the "subject" interface. You can use anything for that: WebServices, DataSnap servers, RemObjects SDK, etc.

Most people wanting a solution like this, go from the traditional client/server application into a multi-tier application. Then the middle-tier can handle all the notifications for you.

Jeroen Pluimers