Delphi — tserversocket and tclientsocket send and receive large data packets

https://www.cnblogs.com/zhangzhifeng/p/6065244.html

When Tserversocket and TclientSocket are sending and receiving relatively large non-blocking data, they may not be received at once and must be received through a loop.

// Embrace

procedure TMAINFORM.TCPServer1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  iLength,I,iStart, iRevCount: Integer;
  iReceived: Integer;
  buff: array of byte;
  S:STRING;
begin
   S:='';
   iStart := 0;
   iLength:= Socket.ReceiveLength;
   iRevcount: = ielength; // добавить здесь
    SetLength(buff, iLength);
    MEMO1.Lines.Add(INTTOSTR(ILENGTH));
   while iLength>0 do
   begin
           iReceived: = socket.receivebuf (buff [iSstart], ielength); // Обратите внимание здесь
             ISTART: = ISSTART + IRECTEPT; // Добавить здесь
     iLength := iLength - iStart;
   end;
       // ниже вашей литой заменяется IREVCount
   FOR I:=0 TO iRevCount -1 DO
     BEGIN
       S:=S+INTTOSTR(BUFF[I]);
     END;
   MEMO1.Lines.Add(S);
   buff:= nil;
end;

  

Send: socket. sendbuf

Leave a Comment