Forum > General

Problems with SimpleIPC in communication between GUI and Console Programs

(1/2) > >>

simone:
I have some problems to implement Interprocess Comunication with SimpleIPC,
in order to allow communication between a GUI program (the server, named ide in
the attached files) and a console program (the client, named prog in the attached files).

I would expect that when I start the server, after pressing the button, it runs the client
that sends a message to show in the memo of server. But this does not happen. Moreover,
if in server code I add Process.Options:=[poWaitOnExit], the client process freezes without
doing anything.

Can someone give me some hint? Many thanks.

CCRDude:
"unit1" is missing in the zip, and since prog.lpr doesn't show {$APPTYPE CONSOLE}, but instead embeds a form, I can only guess it's not really a console program, but a standard GUI program.

simone:
Unit1 is missing because does not exist such unit in the project. prog.lpr is an unused file.

However I attach a new zip for your suggestions.

simone:
For convenience, I report the code on the web page.

This is the server code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program ide; {$mode objfpc}{$H+} uses  Interfaces, Forms, unit2; {$R *.res} begin  RequireDerivedFormResource:=True;  Application.Initialize;  Application.CreateForm(TForm1, Form1);  Application.Run;end.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, SimpleIpc, FileUtil, Forms, Controls, Graphics, Dialogs,  StdCtrls, ExtCtrls, Process; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    Panel1: TPanel;    SimpleIPCServer: TSimpleIPCServer;    SimpleIPCServer1: TSimpleIPCServer;    procedure Button1Click(Sender: TObject);    procedure SimpleIPCServer1MessageQueued(Sender: TObject);  private    Process : TProcess;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  SimpleIPCServer:=TSimpleIPCServer.Create(nil);  SimpleIPCServer.ServerID:='simone';  SimpleIPCServer.Global:=True;  SimpleIPCServer.OnMessageQueued:=@SimpleIPCServer1MessageQueued;  SimpleIPCServer.StartServer(False);   Process:=TProcess.Create(nil);  if FileExists('prog.exe') then    begin      Process.Executable:='prog.exe';      //Process.Options:=[poWaitOnExit];      Process.Execute;    end;  Process.Free;  SimpleIPCServer.Free;end; procedure TForm1.SimpleIPCServer1MessageQueued(Sender: TObject);var  Msg : string;begin  SimpleIPCServer.ReadMessage;  Msg:=SimpleIPCServer.StringMessage;  Memo1.Lines.Add(Msg);end; end.
This is the client code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program prog;{$mode objfpc}{$H+}uses  Classes,SimpleIpc,SysUtils;var  SimpleIPCClient: TSimpleIPCClient;begin  SimpleIPCClient:=TSimpleIPCClient.Create(nil);  SimpleIPCClient.ServerID:='simone';  if SimpleIPCClient.ServerRunning then    begin      SimpleIPCClient.Connect;      SimpleIPCClient.SendStringMessage('Hello!');    end;  SimpleIPCClient.Free;end.
Thanks in advance for the help.

ASerge:

--- Quote from: simone on January 07, 2019, 04:07:55 pm ---Thanks in advance for the help.

--- End quote ---
Add after Process.Execute; SimpleIPCServer.PeekMessage(MSecsPerSec, False); or use SimpleIPCServer1

Navigation

[0] Message Index

[#] Next page

Go to full version