Page 1 of 1

Notification on MySQL

PostPosted: December 2nd, 2007, 1:00 am
by Kambiz
I have to write a stupid application that uses a remote MySQL as database. Each instance of this application needs to be notified about changes made by other instances on the database in real time.

Whether I need a middle ware application to manage notifications, or is there an easier solution?

Thank you.

PostPosted: December 7th, 2007, 5:12 pm
by sepehr
if you use transactions you don't need to notify other clients about changes,
search for transactions in mysql ;)

Ps:don't call my favorite database stupid man ;)

PostPosted: December 7th, 2007, 7:52 pm
by Kambiz
I don't use transaction because I don't need it. Using transactions makes the database operations slower.

As solution, I used a pair of MultiCast TCP server and client in my application to notify other instances when something critical has been changed.

By the way, I called my application stupid, not MySQL.

PostPosted: December 8th, 2007, 4:58 am
by john123
second solution is,
(Windows Messaging)
,
& third solution is (Creating Shared Memory),{CreateFileMapping &...}

PostPosted: December 8th, 2007, 8:35 am
by Kambiz
Do mapped files and Windows messages work across network? :-k

PostPosted: December 8th, 2007, 10:07 am
by john123
No,
these don't work across network. [-X
these are for system wide communicate on a single computer between Applications.
for across network,
I think your solution is good.
what is your problem with your solution?

PostPosted: December 8th, 2007, 8:03 pm
by Kambiz
Actually nothing! :)

Just wanted to prevent doing something which could be already available as built-in.

PostPosted: December 9th, 2007, 3:01 pm
by sepehr
Kambiz wrote:I don't use transaction because I don't need it. Using transactions makes the database operations slower.

As solution, I used a pair of MultiCast TCP server and client in my application to notify other instances when something critical has been changed.
.

hmm,would it be much faster to worth using? if so would you share more light on it ;)

PostPosted: December 10th, 2007, 5:20 am
by Kambiz
When each instance of my program does a database operation, it broadcasts a message across the network with the following information:
  • Table Name (actually ID)
  • Operation which can be either Insert, Update, or Delete
  • Record ID
When an instance receives this kind of message (even the message owner) it broadcasts it as a Windows message to all the open forms. Eventually, each form processes the Windows message to update its current state.

As I already said, I use MultiCast protocol (Indy implementation) to broadcast the message. But notice that MultiCast does not work on a machine without network connection (a socket error occurs).

Here is the actual code in my application:

Code: Select all
// broadcast the message to the application's forms
procedure TDM.LocalBroadcast(const Message: TMessage);
var
  I: Integer;
begin
  for I := 0 to Screen.FormCount - 1 do
    with Screen.Forms[I] do
      if HandleAllocated then
        PostMessage(Handle, Message.Msg, Message.WParam, Message.LParam);
end;

// broadcasts the message accross the network
procedure TDM.NetworkBroadcast(const Message: TMessage);
begin
  if MultiCastServer.Active then { are we connected to a network? }
    MultiCastServer.SendBuffer(Message, SizeOf(Message))
  else
    LocalBroadcast(Message);
end;

// dispatch meesages received from network to the application's forms
procedure TDM.MultiCastClientIPMCastRead(Sender: TObject; AData: TStream;
  ABinding: TIdSocketHandle);
var
  Message: TMessage;
begin
  AData.Position := 0;
  while AData.Read(Message, SizeOf(Message)) = SizeOf(Message) do
    LocalBroadcast(Message);
end;