Keep in mind that for a server side implementation of named pipes, you must run Windows NT. Windows 95 does not support named pipe servers.

Also when testing this, beware of NT security issues. If you pass NIL as a security descriptor the only person that can connect to the server will be the one that started the server.

The server example is quite simple and allows only one client connection. If several clients must be serviced at the same time, the server should spawn a new thread or process for each client connect.

best regards

-- Jan Holst Jensen, Denmark

========
program PipeClnt;

// Delphi 2.0 Pipe client that connects to PipeSrv.
// Console application.
//
// JHJe 1996-12-04

uses
  Windows, SysUtils, PipeObjs;

var
  Pipe: TPipeClient;
  BrokenPipe: Boolean;
  buf: AnsiString;

begin
  Pipe:= TPipeClient.Create('\\.\pipe\TestServer');
  repeat
    Readln(buf);
    if buf <> '' then begin
      Pipe.WriteStr(buf + #13#10);
      Pipe.ReadStr(buf);
      write('From server: ', buf);
    end;
  until buf = '';
  Pipe.Free;
end.

============


program PipeSrv;

// Delphi 2.0 Pipe server that echoes input after having uppercased it.
// Console application.
//
// JHJe 1996-12-04

uses
  Windows, SysUtils, PipeObjs;

const
  CR = #13;
  LF = #10;
  CRLF = CR + LF;

var
  Pipe: TPipeServer;
  BrokenPipe: Boolean;
  buf: AnsiString;
  sa: TSecurityAttributes;

begin
  writeln('Halt with ^C');
  // Set NIL security
  sa.nLength:= sizeOf(sa);
  sa.bInheritHandle:= false;
  sa.lpSecurityDescriptor:= nil;
  while true do begin
    try
      Pipe:= TPipeServer.Create('\\.\pipe\TestServer', sa);
    except
      on E: Exception do begin
        writeln(E.Message);
        halt(1);
      end;
    end;
    { Wait for client to connect }
    if not Pipe.Connect then begin
      Writeln('Connect failed');
      Pipe.Destroy;
      halt(2);
    end;
    { Client is connected, process input }
    writeln('Client has connected!');
    BrokenPipe:= false;
    repeat
      try
        Pipe.ReadStr(buf);
      except
        BrokenPipe:= true;
      end;
      if not BrokenPipe then
        Pipe.WriteStr(UpperCase(buf));
    until BrokenPipe;
    { Clean up }
    Pipe.Free;
  end; // while
end.

