Hello, i'm new to RTC components
I'm trying to copy files between a server and a client.
I have created both server and client applications using code from the demos and the classroom examples.
I'm close to do the task. My problem is that the destination files are created with size 0.
The code i'm using is shown below. Any idea what could be the problem ?
thanks
Roberto
Delphi XE2, Windows 7
RTC ver. 6.38
Server side:
var
MAX_SEND_BLOCK_SIZE:int64=1460*44;
MAX_ACCEPT_BODY_SIZE:int64=128000;
// TRCTDATAPROVIDER events --------------------------------------------
procedure Trtc_server_dm.rdp_filesCheckRequest(Sender: TRtcConnection);
var
vsFileName : string;
begin
with TRtcDataServer(Sender) do
begin
vsFileName := Request.FileName;
Accept;
Request.Info['fname'] := vsFileName;
Response.ContentLength:=File_Size(vsFileName);
WriteHeader;
end;
end;
// event assigned to ONDATARECEIVED and ONDATASENT
procedure Trtc_server_dm.rdp_filesDataReceived(Sender: TRtcConnection);
var
vsFileName : string;
viSent : integer;
begin
with TRtcDataServer(Sender) do
if Request.Complete then
begin
if Response.ContentLength > Response.ContentOut then
begin
vsFileName := Request.Info['fname'];
if File_Exists(vsFileName) then
begin
if File_Size(vsFileName) = Response.ContentLength then
begin
viSent := Response.ContentLength - Response.ContentOut;
if viSent > 16000 then viSent := 16000;
Write(Read_File(vsFileName, Response.ContentOut, viSent) );
end
else
Disconnect;
end
else
Write('File not found on server: ' + vsFileName);
end;
end;
end;
CLIENT SIDE:
// TRCTDATAREQUEST EVENTS ---------------------------------------------------
procedure Trtc_client_dm.datarequestBeginRequest(Sender: TRtcConnection);
begin
with TRtcDataClient(Sender) do
begin
WriteHeader;
// No Body.
end;
end;
procedure Trtc_client_dm.datarequestDataReceived(Sender: TRtcConnection);
var
s:RtcString;
begin
with TRtcDataClient(Sender) do
begin
if not inMainThread then
Sync(datarequestDataReceived)
else begin
if Response.Started then
begin
if Request.info.asText['fname']<>'' then
begin
if not DirectoryExists(ExtractFilePath(ExpandFileName(Request.info.asText['fname']))) then
ForceDIrectories(ExtractFilePath(ExpandFileName(Request.info.asText['fname'])));
Delete_File(request.Info.asText['fname']);
end;
end;
s:=Read;
if Request.Info.asText['fname']<>'' then
Write_File(Request.Info.asText['fname'], s, Response.ContentIn-length(s))
else if Request.Info.asString['data']='' then
Request.Info.asString['data']:=s;
end;
end;
end;
// I'm using this procedure to copy a file from remote server to local
// datarequest is a TRCTDATAREQUEST object.
procedure Trtc_client_dm.copy_file(fi,fo:string);
// fi=remote file name
// fo=local file name
begin
with datarequest do
begin
with Request do
begin
Method:=RtcString('GET');
FileName:=fi;
Query.Text:=RtcString('');
Info.asText['fname']:=fo;
end;
Post;
end;
end;