Base TCP client class updates
This commit is contained in:
parent
8796ac66f4
commit
7232c7360b
|
@ -13,11 +13,12 @@ Type
|
||||||
TTCPClient = Class
|
TTCPClient = Class
|
||||||
Client : TIOSocket;
|
Client : TIOSocket;
|
||||||
ResponseType : Integer;
|
ResponseType : Integer;
|
||||||
|
ResponseStr : String;
|
||||||
ResponseData : TStringList;
|
ResponseData : TStringList;
|
||||||
|
|
||||||
Constructor Create;
|
Constructor Create; Virtual;
|
||||||
Destructor Destroy; Override;
|
Destructor Destroy; Override;
|
||||||
Function Connect (Address: String; Port: Word) : Boolean;
|
Function Connect (Address: String; Port: Word) : Boolean; Virtual;
|
||||||
Function SendCommand (Str: String) : Integer;
|
Function SendCommand (Str: String) : Integer;
|
||||||
Function GetResponse : Integer;
|
Function GetResponse : Integer;
|
||||||
End;
|
End;
|
||||||
|
@ -53,8 +54,9 @@ Begin
|
||||||
|
|
||||||
If Client.FSocketHandle = -1 Then Exit;
|
If Client.FSocketHandle = -1 Then Exit;
|
||||||
|
|
||||||
|
Client.PurgeInputData(1);
|
||||||
|
|
||||||
Client.WriteLine(Str);
|
Client.WriteLine(Str);
|
||||||
//WriteLn(Str);
|
|
||||||
|
|
||||||
Result := GetResponse;
|
Result := GetResponse;
|
||||||
End;
|
End;
|
||||||
|
@ -62,29 +64,31 @@ End;
|
||||||
Function TTCPClient.GetResponse : Integer;
|
Function TTCPClient.GetResponse : Integer;
|
||||||
Var
|
Var
|
||||||
Str : String;
|
Str : String;
|
||||||
|
Res : LongInt;
|
||||||
Begin
|
Begin
|
||||||
Result := -1;
|
Result := -1;
|
||||||
|
|
||||||
If Client.FSocketHandle = -1 Then Exit;
|
If Client.FSocketHandle = -1 Then Exit;
|
||||||
|
|
||||||
If Client.ReadLine(Str) > 0 Then Begin
|
If Client.WaitForData(10000) > 0 Then
|
||||||
ResponseType := strS2I(Copy(Str, 1, 3));
|
If Client.ReadLine(ResponseStr) > 0 Then Begin
|
||||||
Result := ResponseType;
|
ResponseType := strS2I(Copy(ResponseStr, 1, 3));
|
||||||
|
Result := ResponseType;
|
||||||
|
|
||||||
//WriteLn(Str);
|
If ResponseStr[4] = '-' Then Begin
|
||||||
|
ResponseData.Clear;
|
||||||
|
|
||||||
If Str[4] = '-' Then Begin
|
Repeat
|
||||||
ResponseData.Clear;
|
Res := Client.ReadLine(Str);
|
||||||
|
|
||||||
Repeat
|
If Res < 0 Then
|
||||||
If Client.ReadLine(Str) <= 0 Then Break;
|
Break;
|
||||||
|
|
||||||
ResponseData.Add(Str);
|
If Res > 0 Then
|
||||||
|
ResponseData.Add(Str);
|
||||||
//WriteLn(Str);
|
Until Copy(Str, 1, 4) = strI2S(ResponseType) + ' ';
|
||||||
Until Copy(Str, 1, 4) = strI2S(ResponseType) + ' ';
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
End.
|
End.
|
||||||
|
|
Loading…
Reference in New Issue