自学RTC——ServerLesson2

a 夏天 提交于 2020-11-06 01:57:48

/SQUARE

  1. 打开上节的工程

  2. 添加组件RtcDataProvider2并设置Server属性为RtcHttpServer1

  3. RtcDataProvider2OnCheckRequest事件中写上代码:

with TRtcDataServer(Sender) do
  if UpperCase(Request.FileName)='/SQUARE' then
    Accept;
  1. RtcDataProvider2OnDataReceived事件中写上代码:
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('......... done.');
    Write('</body></html>');
    end;
end;
  1. 编译并运行

  2. 打开浏览器,分别访问网址http://localhost/squarehttp://localhost/time

细节

  • TRtcDataProvider只响应自己接收的请求,互不干涉

  • TRtcDataServer(Sender) VS Sender as TRtcDataServer,考察下as强转的效果和区别

  • 使用多个write()与使用一个效果一样

带参数的/SQUARE

  1. 修改RtcDataProvider2OnDataReceived事件的代码为:
var
  cnt,line:integer;
begin
with TRtcDataServer(Sender) do
  if Request.Complete then
    begin
    Write('<html><body>');
    Write('Here comes a table of square values ... <br>');
    cnt:=0;
    if Request.Query['cnt']<>'' then
      try
        cnt:=StrToInt(Request.Query['cnt']);
      except
      end;
    if (cnt<1)or (cnt>1000) then
      begin
      cnt:=10;
      Write('Wrong "cnt" parameter.');
      Write('Using default value of 10.<br>');
      end;
    for line:=1 to cnt do
      begin
      Write('Square of '+IntToStr(line)+' = '+IntToStr(line*line));
      Write('<br>');
      end;
    Write('......... done.');
    Write('</body></html>');
    end;
end;
  1. 编译并运行

  2. 打开浏览器,分别访问网址http://localhost/squarehttp://localhost/square?cnt=30http://localhost/square?cnt=5392

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!