Hello!
I have been testing with the OverbyteIcsBinCliDemo and the OverbyteIcsTcpSrv examples.
From what I have learned, when the Client asks for binary data, one need to send the next request:
binary [size] + #13#10
So it is recognized at the Server example and sends back the following answer, followed by the Id-Header and the payload.
Client.SendStr('200 OK Binary ' + IntToStr(I) +
' bytes requested'#13#10);
The Client looks for the "200 Ok Binary" substring to understand the binary transfer will follow up. This change the receiving mode to Binary.
The first binary data consists of a 4 byte ID and a 4 byte data size.
THdrRec = record
case Integer of
0: (
ID1 : Byte;
ID2 : Byte;
ID3 : Byte;
ID4 : Byte;
SizeLo : Word;
SizeHi : Word);
1: (
ID : Longint;
Size : LongInt);
end;
Then, the Server example will send as many bytes as the Size indicated to the Client, ended with an "E" character.
Have been working with the examples to use for a file transfer between the ESP32 and the computer.
I have used the 4 bytes header to send the file size.
I have adjusted the ESP32 side for a binary message write of 2048 bytes. The OverbyteIcsBinCliDemo receives the data chunks and I direct it to a filestream so the file is built. All this works great at this point. So far with the BinCliDemo fairly modified to save the file, I get a file transfer speed of 100 Kbyte/second (around 800 kbps). Files receives ok, no corruption. This a really exciting experience to see how the file 'downloads' from the ESP32.
Now I'm at the step to improve the speed for the data transfer. I have tried to increase the ESP32 buffer size but this will not work as the MTU is limited. I tried different sizes anyway and with higher values the time increases as errors are produced as packet re-transmission or duped packets.
If the data transmission speed is limited by the healthy handshaking of the TCP client connection and MTU limitation, I come with my beginner idea of using two client connections to send the half of the file over each one. My thoughts are; if I can process each independent client data on a separate buffers/process, I would be able to get the two halves of the file (say 1 mbyte + 1 mbyte) and join in the correct order.
This way, each client will keep handling its packet sizes and Ack's, the Router has enough bandwidth to handle this and more, and for the ESP32 side I have ready about how to send to 2 clients the same file, half one, half the other.
For the Delphi side I expect to receive each part in a memory buffer 'same time' and put together at the end.
The thing is; I'm now wondering how to work at the BinCliDemo to receive the two clients simultaneously. From the ICS library's, as it works asynchronously looks it is possible. But as the example is, it handles received data from one client only. or at least, that is what I think.
I looked around the code over and over and still do not have a good start point. Ideas come and go but when i looks I have found a way, further thinking invalidates the idea... : )
I also look in the first example of the FileSend/FileReceive where the connected Client can be indexed, say as "Client[0]", "Client[1]", etc.
Probably I'm trying to do in the worst way?
Question is,
Could you bring some direction, general advice how/where to start, to handle two client connections data independently...?
PD: Forgot to say, the idea is to have the two clients on separated TCP ports. Say port 23 and port 24 so each one handle its own packet processing.