自学RTC——DualServer

从其它平台迁移而来 在窗体上放4个TRtcHttpServer,依次设置ServerPort为:80、443、8080和8090,并分别命名为HS80、HS443、HS8080和HS8090 再放3个TRtcDualDataServerLink到窗体上,分别命名为DL80and443、DL8080and8090和DLall 设置DL80and443的Server属性为HS80,Server2属性为HS443;设置DL8080and8090的Server属性为HS8080,Server2属性为HS8090 设置DLall的Link属性为DL80and443,Link2属性为DL8080and8090 再放1个TRtcDataProvider到窗体上,设置Link属性为DLall,并在OnCheckRequest事件里写上代码: 1 2 3 4 5 with TRtcDataServer(Sender) do begin Accept; Write('you are on Server ' + ServerPort); end; 在窗口OnShow事件里启动所有TRtcHttpServer,在OnClose事件里停止所有TRtcHttpServer 编译运行 在浏览器里分别访问http://localhost:80、http://localhost:443、http://localhost:8080、http://localhost:8090 注意:TRtcDualDataServerLink只能选择设置Server*或Link*!

2020-11-22 14:54:39 · 1 分钟 · 慢步道人

RTC组件关系图

从其它平台迁移而来

2020-11-10 21:26:27 · 1 分钟 · 慢步道人

自学RTC——BrowserUpload

从其它平台迁移而来 核心代码 OnCheckRequest事件中的代码: 1 2 3 with TRtcDataServer(Sender) do if Request.FilePath.Equal(0, 'UPLOAD') then Accept; OnDataReceived事件中的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 var fname: string; cnt: integer; begin with TRtcDataServer(Sender) do begin if Request....

2020-11-10 20:04:07 · 2 分钟 · 慢步道人

自学RTC——ServerLesson4

从其它平台迁移而来 对于上节的示例中,比较适合发送小文件,若直接用于发送大文件的话,很容易把服务器的内存资源耗尽。当请求大文件时,可以限制每次发送大文件时使用的内存大小(例如16000 B)。 打开上节的工程 修改RtcDataProvider3的OnCheckRequest事件: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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; Response.ContentLength := File_Size(fname); WriteHeader; end; end; end; 修改RtcDataProvider3的OnDataReceived事件: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 var fname: string; len: cardinal; begin with TRtcDataServer(Sender) do if Request....

2020-11-07 23:47:54 · 2 分钟 · 慢步道人

自学RTC——ServerLesson3

从其它平台迁移而来 /test.txt 打开上节的工程 添加组件RtcDataProvider3并设置Server属性为RtcHttpServer1,设置CheckOrder属性为900,使得RtcDataProvider3所处理的请求在其它请求之后(CheckOrder越小越先处理) 在当前exe所在路径下创建一个data文件夹,并在该文件夹内新建一个有内容的test.txt,然后编写一个GetFullFileName函数,用于从请求中提取文件名并转化为本地文件名 1 2 3 4 5 6 7 8 9 10 11 12 13 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; 在RtcDataProvider3的OnCheckRequest事件中写上代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 var fname: string; begin with TRtcDataServer(Sender) do begin fname := GetFullFileName(Request....

2020-11-07 20:27:36 · 1 分钟 · 慢步道人

自学RTC——ServerLesson2

从其它平台迁移而来 /SQUARE 打开上节的工程 添加组件RtcDataProvider2并设置Server属性为RtcHttpServer1 在RtcDataProvider2的OnCheckRequest事件中写上代码: 1 2 3 with TRtcDataServer(Sender) do if UpperCase(Request.FileName)='/SQUARE' then Accept; 在RtcDataProvider2的OnDataReceived事件中写上代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var line:integer; begin with TRtcDataServer(Sender) do if Request.Complete then begin Write('<html><body>'); Write('Here comes a table of square values ... <br>'); for line:=1 to 100 do begin // 使用3个 write 和使用1个效果是一样的 Write('Square of '+IntToStr(line)+' = '); Write(IntToStr(line*line)); Write('<br>'); end; Write('....

2020-11-05 23:34:37 · 1 分钟 · 慢步道人

自学RTC——ServerLesson1

从其它平台迁移而来 RTC全称RealThinClient,据说是Delphi做三层的神器之一,虽然听说已久,却始终未好好研究过,而且安装包里带的有示例源码,于是乎,索性拿这些源码开这么个系列,督促下自己。 步骤 创建一个新工程 从RTC Server组件页中找到RtcHttpServer组件放到窗体上 设置RtcHttpServer1的ServerPort属性为80 在窗体的OnCreate事件里写上代码: 1 RtcHttpServer1.Listen; 从RTC Server组件页中找到RtcDataProvider组件放到窗体上 设置RtcDataProvider1的Server属性为RtcHttpServer1 在RtcDataProvider1的OnCheckRequest事件中写上代码: 1 2 3 with Sender as TRtcDataServer do if UpperCase(Request.FileName)='/TIME' then Accept; 在RtcDataProvider1的OnDataReceived事件中写上代码: 1 2 3 with Sender as TRtcDataServer do if Request.Complete then Write('Current time is: '+TimeToStr(Now)); 编译并运行 打开浏览器,访问网址http://localhost/time 示例源码 核心源码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 procedure TForm1....

2020-11-05 20:51:13 · 2 分钟 · 慢步道人