RealThinClient web server指南.docx

上传人:b****6 文档编号:7260331 上传时间:2023-01-22 格式:DOCX 页数:54 大小:1.92MB
下载 相关 举报
RealThinClient web server指南.docx_第1页
第1页 / 共54页
RealThinClient web server指南.docx_第2页
第2页 / 共54页
RealThinClient web server指南.docx_第3页
第3页 / 共54页
RealThinClient web server指南.docx_第4页
第4页 / 共54页
RealThinClient web server指南.docx_第5页
第5页 / 共54页
点击查看更多>>
下载资源
资源描述

RealThinClient web server指南.docx

《RealThinClient web server指南.docx》由会员分享,可在线阅读,更多相关《RealThinClient web server指南.docx(54页珍藏版)》请在冰豆网上搜索。

RealThinClient web server指南.docx

RealThinClientwebserver指南

RealThinClientwebserver指南

YourfirstWebServer(Lesson1)

We’regoingtobuildaWebServerwithRealThinClientSDKinDelphi.

Basicallywearegoingto:

∙CreateaProject

∙AddtwoRealThinClientSDKcomponents(RtcHTTPServerandRtcDataProvider)

∙Configurethreeevents.

∙CheckthatourWebServerisworking.

We’llbeworkingthecodesectionsintwoformats,oneusingthe with clauseandanotherwithoutit.

Steps.

1.CreateanewVCLFormsproject.

InRADStudio,gotoFile->New

CreateanewVCLFormsProjectinDelphi

AfterthisweshouldhaveanewVLCFormcreated.

NewProjectCreatedwithaVCLFormreadytouse

2.AddaRtcHttpServercomponenttoourForm.

Weaddone RtcHttpServer componentfromourcomponentspalette,itshouldbeinthe RTCServergroup.Weareusing RtcHttpServer ComponentbecausewearegoingtocreateanEXEfile,ifwewouldliketogotheDLLwaywithISAPI,thenwewilluse TRtcISAPIServer.

RtcHttpServerComponentinthecomponentspalette

TakeitanddragittotheForm1area.

RtcHttpServerComponentOnForm1

Now,wehaveourcomponentreadytobeused.Weshouldsettheportinwhichourserverwilllistenforrequests,Normally,allwebserverslistenbydefaultonPort80.SowewillmakeourportlisteninPort80,unlessyouhaveanotherwebserverinstalledinyourmachineandlisteninginPort80,youhavetouseanotherport.

Tosettheportwegotoourcomponentproperties.IfyouhavenotselectedtheRtcHttpServer1component,clickonitandgotothepropertiessection.Ifyoudon’tseethepropertieswindowinyourscreen,pressF11.Inthepropertieswindowwewilllookforapropertycalled ServerPort andsetit’svalueto80.ForthisexampleweareusingjustoneServerlisteningonPort80butwemayseveralServersinthesameapplicationlisteninginseveralports.

ServerPortProperty

3.MaketheRtcHttpServer1componentstartlisteningwhenourFormiscreated.

Nowwehavetoinstructour RtcHttpComponent tostartlisteningforrequestsassoonastheformiscreatedandourapplicationstarted.Todothis,weselectour Form1 anddoubleclickonit,or,selectourForm1,gotopropertieswindow,clickonEventstabandthenclickontheOnCreateevent.Delphiwillcreatethehandlerforthe OnCreate()eventandwillshowitonscreen.

FormCreateEvent

Wemustaddthecodetothe FormCreate event.Thisisbecausewewantour RtcHttpServer tostartlisteningforrequestsassoonastheapplicationstartsitsexecutionsowedon’tneedanyotherkindofcontrolstostartourserver.

Code:

1

2

3

4

procedureTForm1.FormCreate(Sender:

TObject);

begin

  RtcHttpServer1.Listen();

end;

Now,the Listen() methodforthe RtcHttpServer componentcanacceptoneparameter:

 Restarting,thisbydefaultissetto False.Thisparameterworksincombinationwith RestartOn.RestartOnallowstodefinethreeproperties:

∙ListenError:

SetthisparametertoTRUEifyouwantyourservertorestartwhentheserviceisnotabletostart.

∙ListenLost:

SetthisparametertoTRUEifyouwantyourservertorestartwhentheservicestopslisteningforrequestsonthedesignatedport.

∙Wait:

Defineshowmuchtimetheservershouldwaitinsecondsbeforetryingtorestarttheservice.

4.AddaRtcDataProvidertoourForm.

Nowthatwehaveourserverreadytolistenforrequests,weaddone RtcDataProvider componenttotheform.Takea TRtcDataProvider componentfromtheRTCServercomponentgroupanddragittothe Form1.Weneeda RtcDataProvider componentbecauseatthismomentwehaveaServerthatislisteningforrequests,butitwillnotknowwhattodoifarequestarrives,so,foreverytypeofrequestthatwewouldliketogiveananswerinourserver,wehavetodefinean RtcDataProvider.

RtcDataProviderOnPalette

NowweshouldhavetwocomponentsinourForm.

RtcDataProviderComponentOnForm

5.SetRtcDataProviderServerpropertytoRtcHttpServer1.

WemustdefinetheServerforthe RtcDataProvider1 component,inthiscasetheServerwillbeRtcHttpServer1.Weneedtodothisbecausewehavetotellour RtcDataProvider componentwhatServerwilluseincasewehaveotherServers(RtcHttpServer components)listeningondifferentports.

RtcDataProviderLinkedtotheServer

OncetheServerforwhich RtcDataProvider componentwillprocessrequestsisdefined,wehavetodefinewhichrequeststhiscomponentwillprocess.

7.DefinetheOnCheckRequesteventforourRtcDataProvidercomponent.

Tocheckforarequestwewilldefinethe OnCheckRequest eventforthe RtcDataProvider component.Aswesaidbefore,wecanhavemultipleServercomponentslisteningondifferentportsinourapplications,andeveryServermayhavemanyDataProvidersawaitingforrequests.Sothe OnCheckRequest willbecalledonceforallDataProviderslinkedtotheServerwhichhavereceivedtherequest,untiloneoftheDataProviders accept it.

Todothis,withour RtcDataProvider componentselected,weclickonEventsonthePropertieswindowandthendoubleclickonthe OnCheckRequest event

RtcDataProvOnCheckRequestEvent

Thecodewindowwillshowussomethinglikethis

RtcDataProviderOnCheckRequestEventCode

Thecodeinthissectionwillbelikethis:

Using with

1

2

3

4

5

6

procedureTForm1.RtcDataProvider1CheckRequest(Sender:

TRtcConnection);

begin

  withSenderasTRtcDataServerdo

    ifUpperCase(Request.FileName)='/TIME'then

      Accept;

end;

Withoutusing with

1

2

3

4

5

6

7

procedureTForm1.RtcDataProvider1CheckRequest(Sender:

TRtcConnection);

  var

    rdsSever:

TRtcDataServerabsoluteSender;

begin

  ifUpperCase(rdsServer.Request.FileName)='/TIME'then

    rdsServer.Accept;

end;

WeareusingSenderas TRtcDataServer sothatwecancompileourapplicationasanstandaloneEXEorasaDLLfile. TRtcDataServer isthebaseclassfor TRtcHttpServer and TRtcISAPIServer,sotokeepcompatibilitywithoutmakinganychangesifwedecidetogoforanyofthesolutions(EXEorDLL),weuseitthisway.

Request.Filename isthecompletefilenamerequestedbytheclient.The Request propertyoftheRtcDataServer componentcanalsogetotherdataasHostname,ContentLengthandType,Queryparameters,HTTPheaders,etc.

Weareacceptingrequestfor“/TIME”.So,inthiscaseanyofthefollowingwillbeprocessed:

∙http:

//localhost/time

∙http:

//localhost/Time

∙http:

//127.0.0.1/TIME

Andanyofitvariations.RememberthatweareconvertingtouppercasethereceivedFileNamerequest,soitwon’tmatterhowtheclientsendstherequestaslongasitisthephrase“/time”.

8.DefinetheOnDataReceivedeventforourRtcDataProvidercomponent.

Now,wedefinethe OnDataReceived eventforthe RtcDataProvider component.OncetheOnCheckRequest eventhasvalidatedthatthe RtcDataProvider shouldaccepttherequest,theOnDataReceived eventiscalledoncetoaccepteverydatapackageuntilallthecontentisreceived,soherewewilldefinewhattheresponseshouldbeforthereceivedrequest.Todothis,withour RtcDataProvidercomponentselected,weclickonEventsatthePropertieswindowandthendoubleclickonthe OnDataReceived event.

RtcDataProviderOnDataReceivedEvent

Thecodewindowwillshowussomethinglikethis

RtcDataProviderOnDataReceivedEventCode

Thecodeinthissectionwilllooklikethis:

Using with

1

2

3

4

5

6

procedureTForm1.RtcDataProvider1DataReceived(Sender:

TRtcConnection);

begin

  withSenderasTRtcDataServerdo

    ifRequest.Completethen

      Write('CurrentTimeis:

'+TimeToStr(Now));

end;

Withoutusing with

1

2

3

4

5

6

7

procedureTForm1.RtcDataProvider1DataReceived(Sender:

TRtcConnection);

  var

    rdsServer:

TRtcDataServerabsoluteSender;

begin

  ifrdsServer.Request.Completethen

    rdsServer.Write('Currenttimeis:

'+TimeToStr(Now));

end;

Thepurposeofthe Request.Complete propertyofthe Sender parameteristocheckifwehavereceivedthecompleterequest,becausethe OnCheckRequest eventcouldbecalledmultipletimes.

Usingthe Read methodonthe Sender parameterwillgiveusthecurrentcontentofthereceiverbuffer,thenclearthereceiverbuffercontent.Andbyusingthe Write method,wecansendourresponsebacktotheClient.

9.Compileandruntheproject.

NowweCompileandRuntheProject.Press F9 andyouwillseethisonthescreeniftherearenoerrorsinthecode

ProjectRunning

10.Openyourwebbrowserandgotohttp:

//localhost/time

IfyouselectedPort80theyoucangotohttp:

//localhost/timetocheckServer’sresponse

BrowserShowingServer´sResponse

However,ifyouhaveaservicealreadyrunninganddeclaredaPortotherthan80youshouldspecifyitinthebrowser’saddressbar,somethinglike http:

//localhost:

81/time where81istheportthatyouassignedtoyourapplication

BrowserWithDifferentPort

WiththisweconcludeourfirstDemofortheRealThinClientSDKComponents.

Filesincludedinthispost:

∙SourceCodeforWebServer

∙PDFFileofthisPost

Thisentrywaspostedin Articles, QuickStart, RTCSDK, WEB(HTML/CSS) on 15/02/2013 by JenaroCenteno.

AboutJenaroCenteno

MynameisJenaroCenteno.I’vebeenworkingintheprogrammingareasince1990,atthattimeinDOSenvironments,afterthatontheWindowsplatform.Afewyearsago,ImeettheDelphiLanguage,andinthatmomentIsaid“WhatthehellIwasdoingwithoutthis?

”.Andthentheadventurestarted. MoreAboutMeHere.

ViewallpostsbyJenaroCenteno →

Postnavigation

← PostingcodeexamplestoRTCForumsServersendingdynamicallygeneratedcontent(Lesson2) →

2thoughtson“YourfirstWebServer(Lesson1)”

1.Pingback:

 RealThinClientSDK–SendingDynamicallyGeneratedContent|RealThinClassroom

2.Pingback:

 RealThinCli

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1