(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program sockserv;

{$APPTYPE CONSOLE}

uses
  SysUtils, IdTCPServer, IdContext, IdGlobal;

type
  THandler = class
    public
      procedure Dump(AContext : TIdContext);
  end;

procedure THandler.Dump(AContext : TIdContext);

var
  buflen, i : integer;
  buf : TBytes;
  
begin
  if AContext.Connection.Socket.Readable then begin
    buflen := AContext.Connection.IOHandler.InputBuffer.Size;
    AContext.Connection.IOHandler.ReadBytes(buf, buflen);
    for i := low(buf) to high(buf) do begin
      write(' ',IntToHex(buf[i], 2));
    end;
    writeln;
  end;
end;

var
  srv : TIdTCPServer;
  h : THandler;

begin
  srv := TIdTCPServer.Create;
  h := THandler.Create;
  with srv.Bindings.Add do begin
    IP := '127.0.0.1';
    Port := 1234;
  end;
  srv.OnExecute := h.Dump;
  srv.Active := true;
  readln;
  h.Destroy;
  srv.Destroy;
end.
