Hi,
I try to exchange messages between two programs via named pipes.
Doesn't work, because they wait forever on opening the pipes even if there is no other program active.
Or crash when another app tries to access the pipes (e.g. cat)
program testserver;
{$MODE Delphi}
uses
Classes,SysUtils,Crt;
var
output: TFileStream;
input: TFileStream;
buffer: String[255];
size: integer;
ctr: integer;
begin
output := TFileStream.Create('input.pipe', fmOpenWrite or fmShareDenyWrite);
input := TFileStream.Create('output.pipe', fmOpenRead or fmShareDenyRead);
try
buffer:='';
ctr:=0;
while not keypressed do begin
size:= input.read(buffer[1], 1);
if (size > 0) then begin
writeln('Request: ', buffer, InttoHex(byte(buffer[1]),2));
if buffer[1] = '#128' then begin // data requested
inc(ctr);
buffer:= IntToStr(ctr) + '.0'#13#10;
end;
writeln('Answer: ', buffer);
output.write(buffer[1], length(buffer));
end;
sleep(200);
end;
finally
output.free;
input.free;
end;
end.
Background:
I have to port an old DOS based app that reads measurements from serial port.
The hardware is still in production, so I don't have access to it.
As you can see, this program is emulating the hardware. the other program looks quite the same, except the file names are opposite and it is requesting data.
I added the fmShareDeny... constants but this did not help.
any idea?
thanks,
Jan