IdSystatUDP.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.3 10/26/2004 10:49:20 PM JPMugaas
  18. Updated ref.
  19. Rev 1.2 2004.02.03 5:44:30 PM czhower
  20. Name changes
  21. Rev 1.1 1/21/2004 4:04:06 PM JPMugaas
  22. InitComponent
  23. Rev 1.0 11/13/2002 08:02:36 AM JPMugaas
  24. }
  25. unit IdSystatUDP;
  26. {
  27. Indy Systat Client TIdSystatUDP
  28. Copyright (C) 2002 Winshoes Working Group
  29. Original author J. Peter Mugaas
  30. 2002-August-13
  31. Based on RFC 866
  32. Note that this protocol is officially called Active User
  33. }
  34. interface
  35. {$i IdCompilerDefines.inc}
  36. uses Classes, IdAssignedNumbers, IdUDPBase, IdUDPClient;
  37. const DefIdSysUDPTimeout = 1000; //one second
  38. type
  39. TIdSystatUDP = class(TIdUDPClient)
  40. protected
  41. procedure InitComponent; override;
  42. public
  43. procedure GetStat(ADest : TStrings);
  44. published
  45. property ReceiveTimeout default DefIdSysUDPTimeout; //Infinite Timeout can not be used for UDP reads
  46. property Port default IdPORT_SYSTAT;
  47. end;
  48. {
  49. Note that no result parsing is done because RFC 866 does not specify a syntax for
  50. a user list.
  51. Quoted from RFC 866:
  52. There is no specific syntax for the user list. It is recommended
  53. that it be limited to the ASCII printing characters, space, carriage
  54. return, and line feed. Each user should be listed on a separate
  55. line.
  56. }
  57. implementation
  58. uses
  59. IdGlobal, SysUtils;
  60. { TIdSystatUDP }
  61. procedure TIdSystatUDP.InitComponent;
  62. begin
  63. inherited;
  64. Port := IdPORT_SYSTAT;
  65. ReceiveTimeout := DefIdSysUDPTimeout;
  66. end;
  67. procedure TIdSystatUDP.GetStat(ADest: TStrings);
  68. var
  69. s : String;
  70. LTimeout : Integer;
  71. LEncoding: IIdTextEncoding;
  72. begin
  73. //we do things this way so that IdTimeoutInfinite can never be used.
  74. // Necessary because that will hang the code.
  75. // RLebeau 1/5/2011: this does not make sense. If ReceiveTimeout is
  76. // IdTimeoutInfinite, then LTimeout will end up still being IdTimeoutInfinite
  77. // because ReceiveTimeout is being read a second time. Shouldn't this
  78. // be specifying a real timeout value instead?
  79. LTimeout := ReceiveTimeout;
  80. if LTimeout = IdTimeoutInfinite then
  81. begin
  82. LTimeout := ReceiveTimeout;
  83. end;
  84. ADest.BeginUpdate;
  85. try
  86. ADest.Clear;
  87. //The string can be anything - The RFC says the server should discard packets
  88. Send(' '); {Do not Localize}
  89. { We do things this way because RFC 866 says:
  90. If the list does not fit in one datagram then send a sequence of
  91. datagrams but don't break the information for a user (a line) across
  92. a datagram.
  93. }
  94. LEncoding := IndyTextEncoding_8Bit;
  95. repeat
  96. s := ReceiveString(LTimeout, LEncoding{$IFDEF STRING_IS_ANSI}, LEncoding{$ENDIF});
  97. if s = '' then begin
  98. Break;
  99. end;
  100. ADest.Add(s);
  101. until False;
  102. finally
  103. ADest.EndUpdate;
  104. end;
  105. end;
  106. end.