Home > Back-end >  In mobile development, IdTCPClient ReadBytes and ReadStream charge two functions are not complete
In mobile development, IdTCPClient ReadBytes and ReadStream charge two functions are not complete

Time:10-04

Who is to use IdTCPClient mobile development? ReadLn no problem, but ReadBytes and ReadStream two functions are not complete, does not make any changes the same code, run under Windows is very normal, don't know if Indy Bug

 
//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 bug

CodePudding 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
  • Related