Einzelnen Beitrag anzeigen

schöni

Registriert seit: 23. Jan 2005
Ort: Dresden
445 Beiträge
 
Delphi 7 Personal
 
#2

Re: Senden an Named Pipe klappt nur zum Server! Warum?

  Alt 7. Feb 2010, 17:27
Hallo DualCoreCpu,

So hier sollte es in beiden Richtungen klappen. Hab ich grad getestet, weil ich das für meine Zwecke auch brauche. Hab ich dann beim Stöbern gefunden.

Programm A:

SERVERSEITE

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
   pch1: shortstring;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateNamedPipe(PChar('\\.\pipe\<test>'),
                          PIPE_ACCESS_DUPLEX or FILE_FLAG_WRITE_THROUGH,
                          PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_NOWAIT,
                          PIPE_UNLIMITED_INSTANCES,
                          1024,
                          1024,
                          50,
                          @FSA);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
   b1 : boolean;
begin
   buffer:= 'Test';
   WriteFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;
Programm B:

CLIENTSEITE

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateFile(PChar('\\.\pipe\<test>'),
                     GENERIC_READ or GENERIC_WRITE,
                     0,
                     @FSA,
                     OPEN_EXISTING,
                     0,
                     0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
begin
   ReadFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;
Damit der Topf nicht explodiert, lässt man es ab und zu mal zischen.
  Mit Zitat antworten Zitat