/test.txt
-
open Last section The engineering of
-
Add the component
RtcDataProvider3
And set upServer
The attribute isRtcHttpServer1
, Set upCheckOrder
The attribute is900
, bringRtcDataProvider3
The request processed follows other requests (CheckOrder
The smaller, the earlier ) -
At present
exe
Create adata
Folder , And create a new one with content in this foldertest.txt
, And then write aGetFullFileName
function , Used to extract a file name from a request and convert it to a local file name
function GetFullFileName(fname: string): string;
var
DocRoot: string;
begin
DocRoot := ExtractFilePath(AppFileName);
if Copy(DocRoot, length(DocRoot), 1) = '\' then
Delete(DocRoot, length(DocRoot), 1);
DocRoot := DocRoot + '\data';
fname := StringReplace(fname, '/', '\', [rfreplaceall]);
Result := ExpandFileName(DocRoot + fname);
if UpperCase(Copy(Result, 1, length(DocRoot))) <> UpperCase(DocRoot) then
Result := '';
end;
- stay
RtcDataProvider3
OfOnCheckRequest
Write code in the event :
var
fname: string;
begin
with TRtcDataServer(Sender) do
begin
fname := GetFullFileName(Request.FileName);
if (fname <> '') and (File_Exists(fname)) then
begin
Accept;
Request.Info['fname'] := fname;
end;
end;
end;
- stay
RtcDataProvider3
OfOnDataReceived
Write code in the event :
procedure TForm1.RtcDataProvider3DataReceived(Sender: TRtcConnection);
var
fname: string;
begin
with TRtcDataServer(Sender) do
if Request.Complete then
begin
fname := Request.Info['fname'];
if File_Exists(fname) then
Write(Read_File(fname))
else
Write;
end;
end;
-
Compile and run
-
Open the browser , Visit website http://localhost/test.txt