Hi Danijel,
I have RtcMessageServer + RtcDataProvider on server side and RtcMessageClient + RtcDataRequest on client side.
On server side I send file to client this way:
procedure TEngineDM.FileDownloadProviderDataReceived(Sender: TRtcConnection);
var
FileName:string;
Len:Cardinal;
begin
with TRtcDataServer(Sender) do
begin
if Request.Complete then
begin
FileName:=Request.Info['DownloadFile'];
if not FileExists(FileName) then
begin
Disconnect;
exit;
end;
if Response.ContentLength>Response.ContentOut then
begin
Len:=Response.ContentLength-Response.ContentOut;
if Len>65535 then
Len:=65535;
Write(Read_File(FileName,Response.ContentOut,Len));
end;
end;
end;
end;
On Client side I receive data this way (client side is C++Builder so, it's C++):
void __fastcall TDefProgressFrm::DownloadFileRequestDataReceived(TRtcConnection *Sender)
{
Rtcinfo::RtcString FileData;
TRtcDataClient *DataClient;
DataClient=(TRtcDataClient *)Sender;
if(DataClient->Response->StatusCode!=200)
{
DataClient->Response->Reject();
return;
}
if(DataClient->Response->Started)
{
if(FileExists(SaveFileName))
DeleteFile(SaveFileName);
}
FileData=DataClient->Read();
Write_File(SaveFileName,FileData,DataClient->Response->ContentIn-FileData.Length());
if(DataClient->Response->Done)
{
ProgressBar->Position=100;
CancelBtn->Caption="OK";
}
else
ProgressBar->Position=int((DataClient->Response->ContentIn/DataClient->Response->ContentLength)*100);
ProgressBar->Properties->Text=ClientDM->MultiLang->Translate("Downloading file from server")+" ("+IntToStr((int)ProgressBar->Position) +" %)";
Update();
}
It's works on small files but fail on large files with Stack owerflow error.
After debugging I notice that FileDownloadProviderDataReceived called many times until entire file is loaded to memory ! After it DownloadFileRequestDataReceived called many times until file saved to disk !
So it's should works this way FileDownloadProviderDataReceived -> DownloadFileRequestDataReceived and repeat
But works this way DownloadFileRequestDataReceived (many times) -> DownloadFileRequestDataReceived (many times)
I file size is large than 500 mb I got Stack overflow. And also entire file is loaded to memory !
Maybe RtcMessageClient/Server not supports partial file transfer ? Or I miss something ?
p.s. RtcMessageClient.MultiThreaded=true, RtcMessageServer.MultiThreaded=true, RtcDataRequest.AutoSyncEvents=true
Thanks for help !