i think i'm pretty much on the same page as
@teddybear.
i've been following this thread (and one similar to it). i'm having
some difficulty understanding it, and i wanted to comment if it's ok.
no one said you have to use async. asynch behavior aside, tcp does
not guarantee sending or receiving packets in "order". it has nothing to
do with b4x. b4x uses the same underlying network and file transfer
protocols as implemented in java and native code used by
commercial servers. it is the same code, not some b4x protocol.
the tcp protocol handles such issues. frankly, it's hard to imagine the
entire system working as well as it does if everybody was following his
own schemes. even if async packets arrive out of sequence (and you
must, for some reason, use async) , you could use the same method
used by tcp to keep track of things.
if someone were to implement zmodem, once an 8-bit serial protocol is
handed over to tcp, the packet which makes up a particular zmodem
packet is wrapped in a tcp packet. tcp basically ignores what you may
have done; its protocol insures error correction and delivery and, if
necessary, piecing together packets that arrive "out of order". it has no idea
what you had to go through to create a packet of zmodem data. tcp is
at work on both sides of the connection. tcp on your side tells the other side
what's coming. tcp on the other side verifies or asks for retransmission. this
occurs more than once for each packet.
reading bytes from a file is usually not done the way you are proposing.
readBytes() in java and C returns the number of bytes read. you choose a
convenient chunk size and stick with it until there are no more bytes to read.
the system tells you when you've reached the end. if you need to pad the
chunk, it would be for the last chunk read.
then there is the matter of storing images in a database, but that's another matter.