GroupTestCase.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. unit GroupTestCase;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, ComCtrls, IdHTTP;
  6. type
  7. TForm3 = class(TForm)
  8. pgc1: TPageControl;
  9. ts1: TTabSheet;
  10. btn1: TButton;
  11. mmo1: TMemo;
  12. procedure btn1Click(Sender: TObject);
  13. private
  14. procedure ShakeHands;
  15. function HandleHandsShaking1(AStr: string): string;
  16. public
  17. { Public declarations }
  18. end;
  19. var
  20. Form3: TForm3;
  21. implementation
  22. uses
  23. LoggerImport, DateUtils, superobject;
  24. {$R *.dfm}
  25. const
  26. CONNECT: Byte = 0;
  27. DISCONNECT: Byte = 1;
  28. EVENT: Byte = 2;
  29. ACK: Byte = 3;
  30. ERROR: Byte = 4;
  31. BINARY_EVENT: Byte = 5;
  32. BINARY_ACK: Byte = 6;
  33. MAX_PROTOCOL_NUM: Byte = 6;
  34. MIN_PROTOCOL_NUM: Byte = 0;
  35. { TForm3 }
  36. procedure TForm3.btn1Click(Sender: TObject);
  37. begin
  38. ShakeHands;
  39. end;
  40. function TForm3.HandleHandsShaking1(AStr: string): string;
  41. var
  42. ACode: Byte;
  43. AStream: TStringStream;
  44. Len: Int64;
  45. begin
  46. Result := '';
  47. AStream := TStringStream.Create(AStr);
  48. try
  49. AStream.Position :=1;
  50. Len := 0;
  51. AStream.Read(ACode, 1);
  52. while ACode <> $FF do
  53. begin
  54. Len := Len * 10;
  55. Inc(Len, ACode);
  56. AStream.Read(ACode, 1);
  57. end;
  58. //Code
  59. AStream.Read(ACode, 1);
  60. Result := AStream.ReadString(AStream.Size - AStream.Position);
  61. finally
  62. FreeAndNil(AStream);
  63. end;
  64. end;
  65. procedure TForm3.ShakeHands;
  66. var
  67. AIdHttp:TIdHTTP;
  68. ResponeStr: string;
  69. begin
  70. AIdHttp:= TIdHTTP.Create(nil);
  71. try
  72. ResponeStr := AIdHttp.get(
  73. Format('http://127.0.0.1:6714/socket.io/?uid=test&EIO=3&transport=polling&t=%d-0',
  74. [(DateTimeToUnix(Now) - 8*60*60) * 1000]));
  75. ResponeStr := HandleHandsShaking1(ResponeStr);
  76. mmo1.Lines.Add(UTF8Decode(ResponeStr));
  77. ResponeStr := AIdHttp.get(
  78. Format('http://127.0.0.1:6714/socket.io/?uid=test&EIO=3&transport=polling&t=%d-0&sid=%s',
  79. [(DateTimeToUnix(Now) - 8*60*60) * 1000, SO(ResponeStr).S['sid']]));
  80. mmo1.Lines.Add(UTF8Decode(ResponeStr));
  81. //http://127.0.0.1:6714/socket.io/?uid=test&EIO=3&transport=polling&t=1426413088298-1&sid=c1j056d1d2HzLjy8AAAa
  82. //ws://127.0.0.1:6714/socket.io/?uid=test&EIO=3&transport=websocket&sid=c1j056d1d2HzLjy8AAAa
  83. // FClient := TTestWebSocketClientConnection.Create(FIP, inttostr(FPort), '/socket.io/1/websocket/'+ResourceName,'-','ws');
  84. // FClient.OnRead := OnRead;
  85. // FClient.OnWrite := OnWrite;
  86. // FClient.OnClose := OnClose;
  87. // FClient.OnOpen := OnOpen;
  88. except
  89. on E: Exception do
  90. begin
  91. Freeandnil(AIdHttp);
  92. // Error(E.Message, 'TGroup.Start');
  93. Exit;
  94. end;
  95. end;
  96. Freeandnil(AIdHttp);
  97. end;
  98. end.