📄 rtcdatasrv.pas
字号:
NOTE: Even though data has been sent out, it doesn't mean that
the other side already received it. It could also be that connection will
break before this package reaches the other end. }
property OnDataOut;
{ This event will be triggered every time a chunk of data
has just come in (received). To know exactly how much of it
has just arrived, use the @Link(TRtcConnection.DataIn) property. }
property OnDataIn;
end;
TRtcDataServerLink=class;
{ @abstract(DataServer Link wrapper) }
TRtcAbsDataServerLink=class(TRtcServerComponent)
private
FServer: TRtcDataServer;
FLink: TRtcDataServerLink;
FOrder: integer;
protected
// @exclude
function CheckLink(Value:TRtcAbsDataServerLink):boolean; virtual;
// @exclude
procedure RemoveLink(Value:TRtcAbsDataServerLink); virtual;
// @exclude
procedure RemoveServer(Value:TRtcDataServer); virtual;
// @exclude
function GetServer: TRtcDataServer; virtual;
// @exclude
procedure SetServer(const Value: TRtcDataServer); virtual;
// @exclude
function GetLink: TRtcDataServerLink; virtual;
// @exclude
procedure SetLink(const Value: TRtcDataServerLink); virtual;
// @exclude
function GetOrder: integer; override;
// @exclude
procedure SetOrder(const Value: integer); virtual;
// @exclude
procedure Call_SessionOpen(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_SessionClose(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_ListenStart(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_ListenStop(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_CheckRequest(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_RequestAccepted(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_ResponseDone(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_DataReceived(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_DataOut(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_DataIn(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_DataSent(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_ReadyToSend(Sender:TRtcConnection); virtual; abstract;
// @exclude
procedure Call_Disconnect(Sender:TRtcConnection); virtual; abstract;
public
// @exclude
constructor Create(AOwner:TComponent); override;
// @exclude
destructor Destroy; override;
published
{ You can link your components (one or more) to a DataServerLink component
by assigning your @Link(TRtcDataServerLink) component to this Link property.
Doing this, you only have to set the Server property for the master
DataServerLink component and don't need to do it for every single
DataSource component. }
property Link:TRtcDataServerLink read GetLink write SetLink;
{ You can also link your components (one or more) directly to your
DataServer connection component by assigning your
@Link(TRtcDataServer) connection component to this Server property.
This is useful if you have some complex functionality implemented
in a single DataSource/DataServerLink component and don't need to drag
the component through another DataServerLink component to get to
your DataServer. }
property Server:TRtcDataServer read GetServer write SetServer;
{ This is the Order in which the components will be asked to
process a request. The smaller this Order number, the sooner
a component will be asked to process a request, compared to
other components connected to the DataServer at the same level.
Since we could have more levels (more DataServerLink components
connected to each other), Order only defines the priority
at the same level.
@html(<br><br>)
For example, if DataSourceA has Order=50 and DataServerLinkB has Order=60,
when both components are assigned to the same parent DataServerLink or directly
to the DataServer, DataSourceA will receive requests for checking before any
component assigned to DataServerLinkB, no matter which Order the components
assigned to DataServerLinkB have. This is because the Order property only
defines the order in the list of components assigned to the same parent
component (DataServerLink or DataSource).
@html(<br><br>)
To make this simpler, just think of this Order as you would of TabOrder
in a Form, where DataServer is the Form, DataServerLink are the Panels and
DataSource are edit controls. TabOrder is defined for each control
inside its parent (TEdit inside TPanel, child TPanel inside parent TPanel
or master TPanel directly on the TForm).
@html(<br><br>)
Order is especially important for components which could handle
same requests, like the PHP source handler and File source handler.
If FileSource handler would have lower order number than the
PHPSource handler, then the PHP soruce handler would never be executed,
because all PHP files would be simply sent out in their source code form
by the File Source handler. This is why the File Source handler has to have
order number bigger that the PHPSource handler and (preferably) be
connected to the same component (DataServerLink or DataServer). }
property CheckOrder:integer read GetOrder write SetOrder default 0;
end;
{ @abstract(DataServer Link, used to group Data Providers)
You can use TRtcDataServerLink components to group several related
@Link(TRtcDataProvider) components. Simply set this component as the
Link property for all your RtcDataSource components, so that
you don't have to set the Server property for every single
TRtcDataProvider component separately. This is useful especially
when the component is used in a datamodule or a form without
dataserver and you need to link all the components to
a DataServer which is on another datamodule or form.
@html(<br><br>)
Check @Link(TRtcAbsDataServerLink) for more info. }
TRtcDataServerLink=class(TRtcAbsDataServerLink)
private
FOnListenStart:TRtcNotifyEvent;
FOnListenStop:TRtcNotifyEvent;
FOnRequestAccepted:TRtcNotifyEvent;
FOnResponseDone:TRtcNotifyEvent;
FOnDisconnect:TRtcNotifyEvent;
FOnSessionOpen:TRtcNotifyEvent;
FOnSessionClose:TRtcNotifyEvent;
protected
// @exclude
FDataServerLinks:TRtcDataServerLinkList;
{ Other Call_ methods are not implemented here,
since only CheckRequest event will be called on the Link,
while all the other events are being called directly on
the AbsDataServerLink component which implements them
(for example, TRtcDataProvider).
@exclude }
procedure Call_CheckRequest(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataReceived(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataOut(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataIn(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataSent(Sender:TRtcConnection); override;
// @exclude
procedure Call_ReadyToSend(Sender:TRtcConnection); override;
// @exclude
procedure AddChildLink(Value:TRtcAbsDataServerLink);
// @exclude
procedure RemoveChildLink(Value:TRtcAbsDataServerLink);
// @exclude
procedure RemoveAllChildLinks;
public
// @exclude
constructor Create(AOwner:TComponent); override;
// @exclude
destructor Destroy; override;
{ ListenStart and ListenStop methods are used for
component initialization on server start and
deinitialization on server stop.
@exclude }
procedure Call_ListenStart(Sender:TRtcConnection); override;
// @exclude
procedure Call_ListenStop(Sender:TRtcConnection); override;
{ Accepted can be used to prepare the Request after it has been accepted.
@exclude }
procedure Call_RequestAccepted(Sender:TRtcConnection); override;
{ ResponseDone can be used to complete thingsprepared with RequestAccepted.
@exclude }
procedure Call_ResponseDone(Sender:TRtcConnection); override;
{ Disconnect can be used for request deinitialization.
@exclude }
procedure Call_Disconnect(Sender:TRtcConnection); override;
{ New Session Open.
@exclude }
procedure Call_SessionOpen(Sender:TRtcConnection); override;
{ Existing Session Closing.
@exclude }
procedure Call_SessionClose(Sender:TRtcConnection); override;
published
{ Event to be triggered when the Server starts listening on the connection.
You can use this event for component initialization. }
property OnListenStart:TRtcNotifyEvent read FOnListenStart write FOnListenStart;
{ Event to be triggered when the Server stops listening on the connection.
You can use this event for component deinitialization. }
property OnListenStop:TRtcNotifyEvent read FOnListenStop write FOnListenStop;
{ Event to be triggered when a child DataProvider component accepts the Request.
You can use this event for request initialization. For example,
you could create a DataTunel and assign it to Tunel, to have reuqest data tunneled. }
property OnRequestAccepted:TRtcNotifyEvent read FOnRequestAccepted write FOnRequestAccepted;
{ Event to be triggered when a response to server has been sent (Response.Done) }
property OnResponseDone:TRtcNotifyEvent read FOnResponseDone write FOnResponseDone;
{ Event to be triggered when connection gets lost after a request was accepted.
You can use this event for component deinitialization. }
property OnDisconnect:TRtcNotifyEvent read FOnDisconnect write FOnDisconnect;
{ Event to be triggered after new Session was opened. }
property OnSessionOpen:TRtcNotifyEvent read FOnSessionOpen write FOnSessionOpen;
{ Event to be triggered before existing Session closes. }
property OnSessionClose:TRtcNotifyEvent read FOnSessionClose write FOnSessionClose;
end;
{ @abstract(DualDataServerLink, used to link Data Providers to two Servers)
You can use TRtcDualDataServerLink components to link several related
@Link(TRtcDataProvider) components to two Servers (for example,
HTTP and HTTPS). Simply set this component as the Link property
for all your RtcDataSource components, then set both Servers as
this components "Server" and "Server2", or "Link" and "Link2" properties.
You can also combine multiple DualDataServerLink components if
you want your code running with more Servers.
@html(<br><br>)
Check @Link(TRtcAbsDataServerLink) for more info. }
TRtcDualDataServerLink=class(TRtcDataServerLink)
private
FServer2: TRtcDataServer;
FLink2: TRtcDataServerLink;
protected
// @exclude
function CheckLink(Value:TRtcAbsDataServerLink):boolean; override;
// @exclude
procedure RemoveLink(Value:TRtcAbsDataServerLink); override;
// @exclude
procedure RemoveServer(Value:TRtcDataServer); override;
// @exclude
function GetServer2: TRtcDataServer; virtual;
// @exclude
procedure SetServer2(const Value: TRtcDataServer); virtual;
// @exclude
function GetLink2: TRtcDataServerLink; virtual;
// @exclude
procedure SetLink2(const Value: TRtcDataServerLink); virtual;
// @exclude
procedure SetServer(const Value: TRtcDataServer); override;
// @exclude
procedure SetLink(const Value: TRtcDataServerLink); override;
protected
// @exclude
procedure SetOrder(const Value: integer); override;
public
// @exclude
constructor Create(AOwner:TComponent); override;
// @exclude
destructor Destroy; override;
// @exclude
procedure Call_RequestAccepted(Sender: TRtcConnection); override;
// @exclude
procedure Call_ResponseDone(Sender: TRtcConnection); override;
// @exclude
procedure Call_Disconnect(Sender:TRtcConnection); override;
published
{ You can link your components (one or more) to a DataServerLink component
by assigning your @Link(TRtcDataServerLink) component to this Link property.
Doing this, you only have to set the Server property for the master
DataServerLink component and don't need to do it for every single
DataSource component. }
property Link2:TRtcDataServerLink read GetLink2 write SetLink2;
{ You can also link your components (one or more) directly to your
DataServer connection component by assigning your
@Link(TRtcDataServer) connection component to this Server property.
This is useful if you have some complex functionality implemented
in a single DataSource/DataServerLink component and don't need to drag
the component through another DataServerLink component to get to
your DataServer. }
property Server2:TRtcDataServer read GetServer2 write SetServer2;
end;
{ @abstract(Data Provider, used to implement events for processing Requests from DataServer)
You can use TRtcDataProvider components to implement event handlers
for different requests and combine them to compile a
Server which can handle any request implemented in those handlers.
@html(<br><br>)
By implementing events specified by this component, then
assigning your @Link(TRtcDataServer) connection component to this
component's @Link(TRtcAbsDataServerLink.Server) property, or
@Link(TRtcDataServerLink) (which also has to be somewhere connected to
the DataServer connection component) to this component's
@Link(TRtcAbsDataServerLink.Link) property, you can simply integrate
diferent request handlers into your DataServer. For example,
a File source (to send files from disk) and a PHP source
(to read php files from disk, process them by PHP parser and
send the resulting page out).
@html(<br><br>)
Check @Link(TRtcAbsDataServerLink) for more info. }
TRtcDataProvider=class(TRtcAbsDataServerLink)
protected
// @exclude
FOnListenStart: TRtcNotifyEvent;
// @exclude
FOnListenStop: TRtcNotifyEvent;
// @exclude
FOnDisconnect: TRtcNotifyEvent;
// @exclude
FOnCheckRequest: TRtcNotifyEvent;
// @exclude
FOnDataReceived: TRtcNotifyEvent;
// @exclude
FOnReadyToSend: TRtcNotifyEvent;
// @exclude
FOnDataOut: TRtcNotifyEvent;
// @exclude
FOnDataIn: TRtcNotifyEvent;
// @exclude
FOnDataSent: TRtcNotifyEvent;
// @exclude
FOnSessionOpen: TRtcNotifyEvent;
// @exclude
FOnSessionClose: TRtcNotifyEvent;
// @exclude
procedure Call_RequestAccepted(Sender:TRtcConnection); override;
// @exclude
procedure Call_ResponseDone(Sender:TRtcConnection); override;
// @exclude
procedure Call_ListenStart(Sender:TRtcConnection); override;
// @exclude
procedure Call_ListenStop(Sender:TRtcConnection); override;
// @exclude
procedure Call_CheckRequest(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataReceived(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataOut(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataIn(Sender:TRtcConnection); override;
// @exclude
procedure Call_DataSent(Sender:TRtcConnection); override;
// @exclude
procedure Call_ReadyToSend(Sender:TRtcConnection); override;
// @exclude
procedure Call_Disconnect(Sender:TRtcConnection); override;
// @exclude
procedure Call_SessionOpen(Sender:TRtcConnection); override;
// @exclude
procedure Call_SessionClose(Sender:TRtcConnection); override;
public
// @exclude
constructor Create(AOwner:TComponent); override;
// @exclude
destructor Destroy; override;
published
{ This event will be mapped as @Link(TRtcServer.OnListenStart) event
to the assigned Server component and called AFTER the Server's
OnListenStart event, for all components. This event can be used
to initialize the component after server starts listening. }
property OnListenStart:TRtcNotifyEvent read FOnListenStart write FOnListenStart;
{ This event will be mapped as @Link(TRtcServer.OnListenStop) event
to the assigned Server component and called BEFORE the Server's
OnListenStop event, for all components. This event can be used
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -