//读取一行命令行,以#13#10结尾
function ReadLine(Buffer: PChar; const S: TSocket; const DelEOL: BOOL): Integer;
var
RecvLen: Integer;
Buf: array[0..0] of Char;
begin
Buf[0] := #0;
Result := 0;
RecvLen := WinSock2.recv(S, Buf, SizeOf(Buf), 0);
while (RecvLen > 0) do begin
Result := Result + RecvLen;
if Buf[0] <> #0 then Buffer[Lstrlen(Buffer)] := Buf[0];
if Buf[0] = LF{#10} then Break;
Buf[0] := #0;
if Result = 1025 then Break;
RecvLen := WinSock2.recv(S, Buf, SizeOf(Buf), 0);
end;
if DelEOL then begin
if Buffer[lstrlen(Buffer) -1] = #10 then Buffer[lstrlen(Buffer) - 1] := #0;
if Buffer[lstrlen(Buffer) -1] = #13 then Buffer[lstrlen(Buffer) - 1] := #0;
end;
end;
var
buffer: array[0..1024] of Char;
Socket: TSocket;
if ReadLine(Buffer, Socket, True) > 0 then
begin
CmdStr := StrPas(Buffer);
end;