您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > RealThinClientwebserver指南
1RealThinClientwebserver指南YourfirstWebServer(Lesson1)We’regoingtobuildaWebServerwithRealThinClientSDKinDelphi.Basicallywearegoingto:CreateaProjectAddtwoRealThinClientSDKcomponents(RtcHTTPServerandRtcDataProvider)Configurethreeevents.CheckthatourWebServerisworking.We’llbeworkingthecodesectionsintwoformats,oneusingthewithclauseandanotherwithoutit.Steps.1.CreateanewVCLFormsproject.InRADStudio,gotoFile-NewCreateanewVCLFormsProjectinDelphiAfterthisweshouldhaveanewVLCFormcreated.NewProjectCreatedwithaVCLFormreadytouse2.AddaRtcHttpServercomponenttoourForm.2WeaddoneRtcHttpServercomponentfromourcomponentspalette,itshouldbeintheRTCServergroup.WeareusingRtcHttpServerComponentbecausewearegoingtocreateanEXEfile,ifwewouldliketogotheDLLwaywithISAPI,thenwewilluseTRtcISAPIServer.RtcHttpServerComponentinthecomponentspaletteTakeitanddragittotheForm1area.RtcHttpServerComponentOnForm1Now,wehaveourcomponentreadytobeused.Weshouldsettheportinwhichourserverwilllistenforrequests,Normally,allwebserverslistenbydefaultonPort80.SowewillmakeourportlisteninPort80,unlessyouhaveanotherwebserverinstalledinyourmachineandlisteninginPort80,youhavetouseanotherport.Tosettheportwegotoourcomponentproperties.IfyouhavenotselectedtheRtcHttpServer1component,clickonitandgotothepropertiessection.Ifyoudon’tseethepropertieswindowinyourscreen,pressF11.InthepropertieswindowwewilllookforapropertycalledServerPortandsetit’svalueto80.ForthisexampleweareusingjustoneServerlisteningonPort80butwemayseveralServersinthesameapplicationlisteninginseveralports.3ServerPortProperty3.MaketheRtcHttpServer1componentstartlisteningwhenourFormiscreated.NowwehavetoinstructourRtcHttpComponenttostartlisteningforrequestsassoonastheformiscreatedandourapplicationstarted.Todothis,weselectourForm1anddoubleclickonit,or,selectourForm1,gotopropertieswindow,clickonEventstabandthenclickontheOnCreateevent.DelphiwillcreatethehandlerfortheOnCreate()eventandwillshowitonscreen.FormCreateEventWemustaddthecodetotheFormCreateevent.ThisisbecausewewantourRtcHttpServertostartlisteningforrequestsassoonastheapplicationstartsitsexecutionsowedon’tneedanyotherkindofcontrolstostartourserver.Code:1234procedureTForm1.FormCreate(Sender:TObject);beginRtcHttpServer1.Listen();end;4Now,theListen()methodfortheRtcHttpServercomponentcanacceptoneparameter:Restarting,thisbydefaultissettoFalse.ThisparameterworksincombinationwithRestartOn.RestartOnallowstodefinethreeproperties:ListenError:SetthisparametertoTRUEifyouwantyourservertorestartwhentheserviceisnotabletostart.ListenLost:SetthisparametertoTRUEifyouwantyourservertorestartwhentheservicestopslisteningforrequestsonthedesignatedport.Wait:Defineshowmuchtimetheservershouldwaitinsecondsbeforetryingtorestarttheservice.4.AddaRtcDataProvidertoourForm.Nowthatwehaveourserverreadytolistenforrequests,weaddoneRtcDataProvidercomponenttotheform.TakeaTRtcDataProvidercomponentfromtheRTCServercomponentgroupanddragittotheForm1.WeneedaRtcDataProvidercomponentbecauseatthismomentwehaveaServerthatislisteningforrequests,butitwillnotknowwhattodoifarequestarrives,so,foreverytypeofrequestthatwewouldliketogiveananswerinourserver,wehavetodefineanRtcDataProvider.RtcDataProviderOnPaletteNowweshouldhavetwocomponentsinourForm.RtcDataProviderComponentOnForm5.SetRtcDataProviderServerpropertytoRtcHttpServer1.WemustdefinetheServerfortheRtcDataProvider1component,inthiscasetheServerwillbeRtcHttpServer1.WeneedtodothisbecausewehavetotellourRtcDataProvidercomponentwhat5ServerwilluseincasewehaveotherServers(RtcHttpServercomponents)listeningondifferentports.RtcDataProviderLinkedtotheServerOncetheServerforwhichRtcDataProvidercomponentwillprocessrequestsisdefined,wehavetodefinewhichrequeststhiscomponentwillprocess.7.DefinetheOnCheckRequesteventforourRtcDataProvidercomponent.TocheckforarequestwewilldefinetheOnCheckRequesteventfortheRtcDataProvidercomponent.Aswesaidbefore,wecanhavemultipleServercomponentslisteningondifferentportsinourapplications,andeveryServermayhavemanyDataProvidersawaitingforrequests.SotheOnCheckRequestwillbecalledonceforallDataProviderslinkedtotheServerwhichhavereceivedtherequest,untiloneoftheDataProvidersacceptit.Todothis,withourRtcDataProvidercomponentselected,weclickonEventsonthePropertieswindowandthendoubleclickontheOnCheckRequesteventRtcDataProvOnCheckRequestEventThecodewindowwillshowussomethinglikethisRtcDataProviderOnCheckRequestEventCodeThecodeinthissectionwillbelikethis:Usingwith123456procedureTForm1.RtcDataProvider1CheckRequest(Sender:TRtcConnection);beginwithSenderasTRtcDataServerdoifUpperCase(Request.FileName)='/TIME'thenAccept;end;Withoutusingwith61234567procedureTForm1.RtcDataProvider1CheckRequest(Sender:TRtcConnection);varrdsSever:TRtcDataServerabsoluteSender;beginifUpperCase(rdsServer.Request.FileName)='/TIME'thenrdsServer.Accept;end;WeareusingSenderasTRtcDataServersothatwecancompileourapplicationasanstandaloneEXEorasaDLLfile.TRtcDataServeristhebaseclassforTRtcHttpServerandTRtcISAPIServer,sotokeepcompatibilitywithoutmakinganychangesifwedecidetogoforanyofthesolutions(EXE
本文标题:RealThinClientwebserver指南
链接地址:https://www.777doc.com/doc-2855168 .html