On 25/02/2025 00:35, Bob Sneidar via use-livecode wrote:
Okay I verified in my actual code. This is problematic if I don’t know how much 
data is actually going to be sent. I ended up with roughly 138,000 bytes before 
it choked. I supposed I could start with 128k chunks then dial it down if it’s 
too much. I wish I know what the limiting factors are because this has to work 
over the internet.

No, please don't start down the path of "dialling down"; the point at which it will fail is highly variable dependent on network conditions.

Your easiest and safest way (or at least, the one I find easiest) is to use the length + data approach.

If you don't know the total amount when you are about to start sending, then you simply package up what you *do* know as a length+data, and use a special case check to know when everything has been sent.

For example, if you were going to send a folder-full of files, you could do something like:

put the files into tFiles
repeat for each line L in tFiles
   put L & CR & URL ("binfile:" & L) into tData
   put format("%012d", the number of bytes in tData) into tLength
   write tLength & tData to socket tWhateverSocketYouLike
end repeat

-- and send an indicator that we are done  - file name + data cannot be zero-length

put format("%012d", 0) into tLength
write tLength to socket tWhateverSocketYouLike


and read it as

on readalltherestofthedata
    read from tWhichSocketYouAreUsing for 12  with gotALength   -- read the length
end readalltherestofthedata

on gotALength pSocket, pData
   if pData = 0 then
      dispatch "alldone"
   else
      read from tWhichSocketYouAreUsing for pData  with gotFileData   -- read the file name and data
   end if
end gotALength


on gotFileData pSocket, pData
   put line 1 of pData into tFileName
   put line 2 to -1 of pData into tData
   dispatch "processafile" with tFileName, tData
   readalltherestofthedata
end gotFileData


(Obviously, the above has been typed into an email - beware typos, etc.)

Alex.

P.S> yes, you could do ""%12d" rather than "%012d" - but if I ever finish up debugging it, I find the leading zeros a useful reminder that it's a fixed length integer. And I'm assuming that 12 digits is easily big enough for any file you are going to send :-)


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to