JIMSMITH 1 Posted Saturday at 10:25 PM I use the indy tidtcpserver with the readbytes method. The code is ReadBytes(Buffer,buffsize, False). The buffsize is set for 1024. I receive varying amounts of data say 7000 bytes. After 6 passes I receive an timeout because ( after the first 6 *1024 = 6144 the last pass only has 7000 - 6144 = 856) only 856 bytes remain and the timeout occurs waiting to fill the buffer. When the timeout happens the bytes appear to remain in the iohandler buffer. The question is what is the best way to get the 6 chunks and the remaining 856 bytes without generating an exception? I prefer to use readbytes because ther could be different types of data other than strings. I hope this make sense and I appreciate assistance in advance. Share this post Link to post
Remy Lebeau 1533 Posted yesterday at 02:52 AM (edited) Calling ReadBytes() with an AByteCount value greater than 0 will wait until the specified number of bytes have arrived in the InputBuffer. So, if you are expecting 7000 bytes then just call ReadBytes() 1 time with AByteCount set to 7000. But, if you don't know ahead of time how many bytes are coming, then you can call ReadBytes() with an AByteCount value less than 0 and it will return however many bytes are currently available in the InputBuffer (if it is empty, ReadBytes() will wait until any bytes arrive first). If you don't want to change your current logic, then you can simply catch the EIdReadTimeout exception and call ReadBytes() again with the AByteCount value set to the IOHandler's current InputBuffer.Size. Edited yesterday at 02:54 AM by Remy Lebeau Share this post Link to post
JIMSMITH 1 Posted yesterday at 04:40 AM 1 hour ago, Remy Lebeau said: Calling ReadBytes() with an AByteCount value greater than 0 will wait until the specified number of bytes have arrived in the InputBuffer. So, if you are expecting 7000 bytes then just call ReadBytes() 1 time with AByteCount set to 7000. But, if you don't know ahead of time how many bytes are coming, then you can call ReadBytes() with an AByteCount value less than 0 and it will return however many bytes are currently available in the InputBuffer (if it is empty, ReadBytes() will wait until any bytes arrive first). If you don't want to change your current logic, then you can simply catch the EIdReadTimeout exception and call ReadBytes() again with the AByteCount value set to the IOHandler's current InputBuffer.Size. Damn! You are awesome. Share this post Link to post