For some reason around 1250 bytes seems the maximum size of a packet (i guess lnet has an upper limit for packet size), so i can't improve much more on that.
This is the limitation of the network.
You can try something like this:
1. client : request file
2. server : send filesize
3. server : send file in chunks
const
BufferSize = 1024;
[snip]
Fs.Free;
end;
end;
4. client : receive file size
5. client : receive file in loop(almost same code as above), you should read until the streamsize becomes equal to the filesize received previously(step 4)
I used a similar, but event based method (like the example on the lnet site, which is supposed to work correctly):
Note that the block_size:=200
procedure TLTCPTest.OnCanSendL(aSocket: TLSocket);
var
Sent,i: Integer;
begin
if (global_packet_index>0) then
begin
repeat
begin
try
BlockRead(F, packet_buffer[5] , block_size, i);
except end;
inc(global_packet_index);
if (i<block_size) then begin
packet_buffer[4]:='3'; // last packet
try
close(f);
except end;
writeln(': upload done ');
global_packet_index:=0;
end;
Sent := FCon.SendMessage(packet_buffer, aSocket); // remember, don't use the aSocket directly!
//writeln('---> ',sent);
end;
until ( (sent=0) or (global_packet_index=0) );
end;
end;
The result : no error events are fired and , sent is always > 0. However the packets are not received correctly even though OnCanSend should handle the network syncing.
Seems to me that everything is correct, but the system just can't handle the speed without any extra syncing. Also note that if i activate the //writeln('---> ',sent); line, more packets are received correctly , which indicates the extra writeln pause makes things better.
But if anybody sees any mistakes in my method, please let me know ..