//in the thread
while(! Terminated & amp; & MainForm - & gt; IdTCPClient1 - & gt; Connected ())
{
MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; CheckForDataOnSource (100);
If (MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; InputBufferIsEmpty ()==false)
{
Int nReceive=MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; The InputBuffer - & gt; Size;
Char Buf [10240].
NReceive=Min (nReceive, sizeof (Buf));
TIdBytes TMP.
MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; ReadBytes (TMP, nReceive);//read data
BytesToRaw (TMP, Buf, nReceive);
MainForm - & gt; FsUpdateFile - & gt; Write (Buf, nReceive);//write file
}
}
CodePudding user response:
A charge is not complete, often receive bai, what bugCodePudding user response:
Not once, but numerous loop charge is not complete,CodePudding user response:
NReceive=MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; The InputBuffer - & gt; Size==1024?Is it because buf [1024], and nReceive> 1024?
Could use the
NReceive=Max (nReceive, sizeof (Buf));
IdTCPClient I used to say anything,
CodePudding user response:
Int nReceive=MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; The InputBuffer - & gt; Size;Char Buf [10240].
NReceive=Min (nReceive, sizeof (Buf));
Take the minimum because buffer allocation is 10240, if more than this size, the first charge 10240 bytes, the rest of the next cycle to receive,
If change to dynamically allocated buffer size, the result of the test is the same, close not the server sends all content:
Int nReceive=MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; The InputBuffer - & gt; Size;
Void * Buf=malloc (nReceive);//dynamically allocated buffer
TIdBytes TMP.
MainForm - & gt; IdTCPClient1 - & gt; The Socket - & gt; ReadBytes (TMP, nReceive);
BytesToRaw (TMP, Buf, nReceive);
MainForm - & gt; FsUpdateFile - & gt; Write (Buf, nReceive);
Free (Buf);//release