RealThinClient web server指南Word下载.docx
- 文档编号:20367293
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:54
- 大小:1.92MB
RealThinClient web server指南Word下载.docx
《RealThinClient web server指南Word下载.docx》由会员分享,可在线阅读,更多相关《RealThinClient web server指南Word下载.docx(54页珍藏版)》请在冰豆网上搜索。
componentfromourcomponentspalette,itshouldbeinthe
RTCServergroup.Weareusing
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
tostartlisteningforrequestsassoonastheapplicationstartsitsexecutionsowedon’tneedanyotherkindofcontrolstostartourserver.
Code:
1
2
3
4
procedureTForm1.FormCreate(Sender:
TObject);
begin
RtcHttpServer1.Listen();
end;
Now,the
Listen()
methodforthe
componentcanacceptoneparameter:
Restarting,thisbydefaultissetto
False.Thisparameterworksincombinationwith
RestartOn.RestartOnallowstodefinethreeproperties:
∙ListenError:
SetthisparametertoTRUEifyouwantyourservertorestartwhentheserviceisnotabletostart.
∙ListenLost:
SetthisparametertoTRUEifyouwantyourservertorestartwhentheservicestopslisteningforrequestsonthedesignatedport.
∙Wait:
Defineshowmuchtimetheservershouldwaitinsecondsbeforetryingtorestarttheservice.
4.AddaRtcDataProvidertoourForm.
Nowthatwehaveourserverreadytolistenforrequests,weaddone
RtcDataProvider
componenttotheform.Takea
TRtcDataProvider
componentfromtheRTCServercomponentgroupanddragittothe
Form1.Weneeda
componentbecauseatthismomentwehaveaServerthatislisteningforrequests,butitwillnotknowwhattodoifarequestarrives,so,foreverytypeofrequestthatwewouldliketogiveananswerinourserver,wehavetodefinean
RtcDataProvider.
RtcDataProviderOnPalette
NowweshouldhavetwocomponentsinourForm.
RtcDataProviderComponentOnForm
5.SetRtcDataProviderServerpropertytoRtcHttpServer1.
WemustdefinetheServerforthe
RtcDataProvider1
component,inthiscasetheServerwillbeRtcHttpServer1.Weneedtodothisbecausewehavetotellour
componentwhatServerwilluseincasewehaveotherServers(RtcHttpServer
components)listeningondifferentports.
RtcDataProviderLinkedtotheServer
OncetheServerforwhich
componentwillprocessrequestsisdefined,wehavetodefinewhichrequeststhiscomponentwillprocess.
7.DefinetheOnCheckRequesteventforourRtcDataProvidercomponent.
Tocheckforarequestwewilldefinethe
OnCheckRequest
eventforthe
component.Aswesaidbefore,wecanhavemultipleServercomponentslisteningondifferentportsinourapplications,andeveryServermayhavemanyDataProvidersawaitingforrequests.Sothe
willbecalledonceforallDataProviderslinkedtotheServerwhichhavereceivedtherequest,untiloneoftheDataProviders
accept
it.
Todothis,withour
componentselected,weclickonEventsonthePropertieswindowandthendoubleclickonthe
event
RtcDataProvOnCheckRequestEvent
Thecodewindowwillshowussomethinglikethis
RtcDataProviderOnCheckRequestEventCode
Thecodeinthissectionwillbelikethis:
Using
with
5
6
procedureTForm1.RtcDataProvider1CheckRequest(Sender:
TRtcConnection);
withSenderasTRtcDataServerdo
ifUpperCase(Request.FileName)='
/TIME'
then
Accept;
Withoutusing
7
var
rdsSever:
TRtcDataServerabsoluteSender;
ifUpperCase(rdsServer.Request.FileName)='
rdsServer.Accept;
WeareusingSenderas
TRtcDataServer
sothatwecancompileourapplicationasanstandaloneEXEorasaDLLfile.
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
//localhost/Time
//127.0.0.1/TIME
Andanyofitvariations.RememberthatweareconvertingtouppercasethereceivedFileNamerequest,soitwon’tmatterhowtheclientsendstherequestaslongasitisthephrase“/time”.
8.DefinetheOnDataReceivedeventforourRtcDataProvidercomponent.
Now,wedefinethe
OnDataReceived
component.OncetheOnCheckRequest
eventhasvalidatedthatthe
shouldaccepttherequest,theOnDataReceived
eventiscalledoncetoaccepteverydatapackageuntilallthecontentisreceived,soherewewilldefinewhattheresponseshouldbeforthereceivedrequest.Todothis,withour
RtcDataProvidercomponentselected,weclickonEventsatthePropertieswindowandthendoubleclickonthe
event.
RtcDataProviderOnDataReceivedEvent
RtcDataProviderOnDataReceivedEventCode
Thecodeinthissectionwilllooklikethis:
procedureTForm1.RtcDataProvider1DataReceived(Sender:
ifRequest.Completethen
Write('
CurrentTimeis:
'
+TimeToStr(Now));
rdsServer:
ifrdsServer.Request.Completethen
rdsServer.Write('
Currenttimeis:
Thepurposeofthe
Request.Complete
propertyofthe
Sender
parameteristocheckifwehavereceivedthecompleterequest,becausethe
eventcouldbecalledmultipletimes.
Usingthe
Read
methodonthe
parameterwillgiveusthecurrentcontentofthereceiverbuffer,thenclearthereceiverbuffercontent.Andbyusingthe
Write
method,wecansendourresponsebacktotheClient.
9.Compileandruntheproject.
NowweCompileandRuntheProject.Press
F9
andyouwillseethisonthescreeniftherearenoerrorsinthecode
ProjectRunning
10.Openyourwebbrowserandgotohttp:
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- RealThinClient web server指南 server 指南