RealThinClientwebserver指南

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1RealThinClientwebserver指南YourfirstWebServer(Lesson1)We’regoingtobuildaWebServerwithRealThinClientSDKinDelphi.Basicallywearegoingto:CreateaProjectAddtwoRealThinClientSDKcomponents(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

1 / 49
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功