Recent

Author Topic: Communication between application instances  (Read 15525 times)

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Communication between application instances
« on: November 15, 2009, 10:28:04 pm »
I have a problem with FindWindow. I have Form1 of class TForm1 and when I use either FindWindow or FindWindowEx it always returns 0. I am using Qt interface.
Second thing is that in Windows I can write custom messages and broadcast them to all windows however in Delphi it is done by writing code for TApplication.OnMessage event. I haven't found it here so the question is can I do that somehow?
Last thing is how can I make communication between different instances of my application under Linux? Or maybe Lazarus itself provides some routines that I could use.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Communication between application instances
« Reply #1 on: November 15, 2009, 10:44:33 pm »
how can I make communication between different instances of my application under Linux? Or maybe Lazarus itself provides some routines that I could use.

There are TSimpleIPCClient and -Server in the System tab.

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Re: Communication between application instances
« Reply #2 on: November 15, 2009, 11:53:22 pm »
Thx, works:-)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Communication between application instances
« Reply #3 on: November 16, 2009, 12:01:01 am »
I'm not an expert, but I think it needs some polling.

For the record: This seems to work for me:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  SimpleIPCServer1.Active:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SimpleIPCClient1.Active:=True;
  SimpleIPCClient1.SendStringMessage('test');
  SimpleIPCClient1.Active:=False;
end;

procedure TForm1.SimpleIPCServer1Message(Sender: TObject);
begin
  Memo1.Lines.Add(SimpleIPCServer1.StringMessage);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if SimpleIPCServer1.Active then SimpleIPCServer1.PeekMessage(1,true);
end;

Troodon

  • Sr. Member
  • ****
  • Posts: 484
Re: Communication between application instances
« Reply #4 on: December 10, 2009, 04:42:50 am »
Do you really need the timer? Shouldn't the IPC Server onMessage handler pick up the message anyway?
« Last Edit: December 10, 2009, 04:48:33 am by Troodon »
Lazarus/FPC on Linux

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Re: Communication between application instances
« Reply #5 on: December 16, 2009, 12:12:47 am »
Do you really need the timer? Shouldn't the IPC Server onMessage handler pick up the message anyway?
Just tried without timer with Linux and it didn't work.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Communication between application instances
« Reply #6 on: December 16, 2009, 08:07:23 am »
There are TSimpleIPCClient and -Server in the System tab.

I've tried it on WinXP. It works fine if the 2 applications run on same PC, But if i put the 2 executables on a directory in my net and then i run a program from a PC and the other program in another PC it don't works. How can i do it works?

Thanks, Mario

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Communication between application instances
« Reply #7 on: December 16, 2009, 10:15:45 am »
I've tried it on WinXP. It works fine if the 2 applications run on same PC, But if i put the 2 executables on a directory in my net and then i run a program from a PC and the other program in another PC it don't works. How can i do it works?

TCP/IP ?

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Communication between application instances
« Reply #8 on: December 16, 2009, 12:23:35 pm »
TCP/IP ?

You means with TTFTPSend?

Thanks, Mario

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Communication between application instances
« Reply #9 on: December 16, 2009, 01:50:08 pm »
You means with TTFTPSend?

You can use a simpler protocol. Afair, there is an echo server example in the synapse distr.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Communication between application instances
« Reply #10 on: December 16, 2009, 04:19:06 pm »
I've tried the echo example, but in "TTCPEchoDaemon.Execute;", where it do "if canread(1000) then", canread is neber true and so the program does nothing

 

TinyPortal © 2005-2018