IdChargenUDPServer.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.4 2004.02.03 5:44:56 PM czhower
  18. Name changes
  19. Rev 1.3 1/21/2004 1:49:36 PM JPMugaas
  20. InitComponent
  21. Rev 1.2 10/24/2003 02:54:50 PM JPMugaas
  22. These should now work with the new code.
  23. Rev 1.1 2003.10.24 10:38:24 AM czhower
  24. UDP Server todos
  25. Rev 1.0 11/14/2002 02:14:08 PM JPMugaas
  26. 2001 - Sep 17
  27. J. Peter Mugaas
  28. Started this with code from Rune Moburg's UDP Chargen Server
  29. }
  30. unit IdChargenUDPServer;
  31. interface
  32. {$i IdCompilerDefines.inc}
  33. uses
  34. IdAssignedNumbers, IdGlobal, IdSocketHandle, IdUDPBase, IdUDPServer;
  35. type
  36. TIdChargenUDPServer = class(TIdUDPServer)
  37. protected
  38. procedure DoUDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle); override;
  39. procedure InitComponent; override;
  40. published
  41. property DefaultPort default IdPORT_CHARGEN;
  42. end;
  43. implementation
  44. { TIdChargenUDPServer }
  45. procedure TIdChargenUDPServer.InitComponent;
  46. begin
  47. inherited InitComponent;
  48. DefaultPort := IdPORT_CHARGEN;
  49. end;
  50. procedure TIdChargenUDPServer.DoUDPRead(AThread: TIdUDPListenerThread;
  51. const AData: TIdBytes; ABinding: TIdSocketHandle);
  52. const
  53. rowlength = 75;
  54. var
  55. s: string;
  56. i, row, ln : integer;
  57. c: Char;
  58. begin
  59. inherited DoUDPRead(AThread, AData, ABinding);
  60. i := 1;
  61. c := '0'; {Do not Localize}
  62. s := ''; {Do not Localize}
  63. ln := Random(512);
  64. Row := 0;
  65. while i <= ln do
  66. begin
  67. if c > #95 then
  68. begin
  69. c := '0'; {Do not Localize}
  70. end;
  71. if i mod (rowlength + 1) = 0 then
  72. begin
  73. s := s + #13;
  74. c := chr(ord('0') + row mod (95 - ord('0'))); {Do not Localize}
  75. inc(row);
  76. end
  77. else
  78. begin
  79. s := s + c;
  80. end;
  81. inc(i);
  82. inc(c);
  83. end;
  84. ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, ToBytes(s), ABinding.IPVersion);
  85. end;
  86. end.