simpleipcserver.lpr 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. program simpleipcserver;
  2. {$mode objfpc}{$H+}
  3. uses
  4. {$IFDEF UNIX}
  5. BaseUnix,
  6. {$ENDIF}
  7. {$IFDEF windows}
  8. Windows,
  9. {$ENDIF}
  10. Classes, SysUtils, CustApp, simpleipc, Crt;
  11. type
  12. { TSimpleIPCServerApp }
  13. TSimpleIPCServerApp = class(TCustomApplication)
  14. protected
  15. procedure DoRun; override;
  16. public
  17. constructor Create(TheOwner: TComponent); override;
  18. end;
  19. { TSimpleIPCServerApp }
  20. procedure TSimpleIPCServerApp.DoRun;
  21. var
  22. IPCServer: TSimpleIPCServer;
  23. Key: Char;
  24. NullObj: TObject;
  25. begin
  26. IPCServer := TSimpleIPCServer.Create(nil);
  27. IPCServer.ServerID:='ipc_test_crash';
  28. IPCServer.Global:=True;
  29. IPCServer.StartServer;
  30. NullObj := nil;
  31. WriteLn('Server started');
  32. WriteLn(' Press e to finish with an exception');
  33. WriteLn(' Press t to terminate through OS api - ', {$IFDEF UNIX}'Kill'{$ELSE}'TerminateProcess'{$ENDIF});
  34. WriteLn(' Press any other key to finish normally');
  35. Key := ReadKey;
  36. case Key of
  37. 'e':
  38. begin
  39. NullObj.AfterConstruction;
  40. end;
  41. 't':
  42. begin
  43. {$ifdef unix}
  44. FpKill(FpGetpid, 9);
  45. {$endif}
  46. {$ifdef windows}
  47. TerminateProcess(GetCurrentProcess, 0);
  48. {$endif}
  49. end;
  50. end;
  51. IPCServer.Active:=False;
  52. WriteLn('Server stopped');
  53. IPCServer.Destroy;
  54. Terminate;
  55. end;
  56. constructor TSimpleIPCServerApp.Create(TheOwner: TComponent);
  57. begin
  58. inherited Create(TheOwner);
  59. StopOnException:=True;
  60. end;
  61. var
  62. Application: TSimpleIPCServerApp;
  63. begin
  64. Application:=TSimpleIPCServerApp.Create(nil);
  65. Application.Title:='IPC Server';
  66. Application.Run;
  67. Application.Free;
  68. end.