I have an asychronous file transfer using boost::asio
.
Multiple files can be transfered at the 'same time'. Same time as in - file packet for file 1, next packet for file 3, next for file 2, ... No threaded file-transfer in the same socket.
Currently I'm sending each time a 10KB packet/message/string, including a small header with OPCode, a GUID, etc, from sender to receiver. When the receiver has received the packet it will send a small acknowledge packet (~20byte +- 4) back to the sender. When the sender has received the packet, it will send the next packet for the corresponding file to the receiver and it starts again.
My question is, if this looks like a reasonable approach, or if there's a better one.
Side note: I'll also use a zip library later in order to send more/less data per packet.
Before using this "style" I just kept 'spamming' all packets from sender-side to receiver-side w/o any acknowledgement. The "packets"/messages are being split, and therefore the application does not recognize the incoming data (no header) as valid and discards it. This basically means the data is lost at the receivers side.
What would you recommend, what is the best approach to send data fast over a TCP (opt. SSL too) connection, assuming both ends have different upload/download rates ?
If you need more information about something specific, please leave a comment.
Edit:
As I send multiple files, my "packets"/messages include, as mentioned above a GUID in the header. Multiple files can be transfered at one time. Sending large data, such as 5MB often splits the message, and this means that at messages w/o the header arrive, and therefore break the system.
One easy solution would be to re-structure my code a little bit and send file by file. This would work if the header is sent once, and right after it the data-/filechunk is sent without header in larger packets. As bЈовић said, TCP will take care of the rest.
In my current "solution"/approach I sadly need the mentioned "system" I've explained. For other transfers except this one, I'm sending file by file and the data is split.