📄 rtcconn.pas
字号:
// @exclude
procedure CallListenLost; virtual;
{ This is a ListenError trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerListenError(E:Exception); virtual;
// @exclude
procedure CallListenError(E:Exception); virtual;
{ This is a Restart trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerRestart; virtual;
// @exclude
procedure CallRestart; virtual;
{ @name sets all parameters for the connection provider,
introduced by the @Link(TRtcServer) connection component.
It calls 'inherited' to set inherited properties.
@exclude }
procedure SetParams; override;
{ @name sets all triggers for the connection provider,
introduced by the @Link(TRtcServer) connection component.
It calls 'inherited' to set inherited triggers.
@exclude }
procedure SetTriggers; override;
{ @name clears all triggers for the connection provider,
introduced by the @Link(TRtcServer) connection component.
It calls 'inherited' to clear inherited triggers.
@exclude }
procedure ClearTriggers; override;
{ @name is a trigger, implementing a Timer event to
restart the listener connection.
@exclude }
procedure OnRestart_Timer; virtual;
public
{ When creating TRtcServer components at runtime,
never use Create(). Always use the NEW class function,
implemented by all RTC connection components. }
constructor Create(AOwner: TComponent); override;
{ To destroy connection component created at runtime,
never use Free or Destroy. Always use the @Link(TRtcConnection.Release) method. }
destructor Destroy; override;
{ Creates a copy of this connection component,
with all properties and events set,
including a new connection provider,
with preset properties and events. }
function copyOf:TRtcServer; virtual;
{ Start listening for incomming connections on specified @Link(TRtcConnection.ServerPort),
bound to a specified @Link(TRtcConnection.ServerAddr). }
procedure Listen; virtual;
{ Stop Listening for incomming connections
and close all open connections as soon as possible. }
procedure StopListen; virtual;
{ Calling this method will create a timer and call Listen
after 'WaitSeconds' seconds. If you call this method with
0 as parameter, default value for RTC_WAIT_BEFORE_RECONNECT will be used. }
procedure Restart(WaitSeconds:integer=0); virtual;
{ Returns TRUE if this is a listener (server) and it is listening. }
function isListening:boolean; virtual;
{ Returns TRUE if this is a client connection,
FALSE if it is the listener. }
function isClient:boolean; virtual;
published
{ By setting this property to True, you do not have to do anything
special to initiate a renewed Listen after specific events occure.
For more information, check @Link(TRtcRestartParam). }
property RestartOn:TRtcRestartParam read FRestartOn write FRestartOn;
{ This will be the first event to trigger when a new client establishes
a new connection with your listening server component.
Same as the 'OnConnect' event, this event will allways be called
from the client connection's thread and with a client connection as parameter.
@html(<br><br>)
If all your client connections will use the same events handlers for all
client connections coming through this server component (this is the
prefered method to use RTC connection components), you don't need to
implement this event handler.
@html(<br><br>)
But, in case you want to use different events for different clients (maybe
depending on the IP address or some other information you get immediatelly
after connect and before any real data has been sent or received, you can
use this event handler to set new events, which will be used instead of
the default event handlers, which you defined for your TRtcServer component. }
property OnClientConnect:TRtcNotifyEvent read FOnClientConnect write FOnClientConnect;
{ This event will be the last event to trigger when a working connection that
came from a client to your listening server gets lost.
Same as the 'OnDisconnect' event, this event will allways be called
from the client connection's thread and with a client connection as parameter.
@html(<br><br>)
This event's primary purpuse is to give you a chance to free the
resources you occupied for this connection. There will be no more
events triggered for this connection after 'OnClientDisconnect'.
@html(<br><br>)
This will be the last event where you can still use the Client connection.
After this event, Client connection and its component will be destroyed.
@longcode(#
NOTE: OnClientDisconnect allways comes in pair with prior OnClientConnect.
OnClientDisconnect will not be triggered for connections
where OnClientConnect was not triggered before.
#) }
property OnClientDisconnect:TRtcNotifyEvent read FOnClientDisconnect write FOnClientDisconnect;
{ Listener was started. This means that we're waiting on a
specific port for incomming connections. This event will be
triggered if the call to "Listen" was succesfull. }
property OnListenStart:TRtcNotifyEvent read FOnOpen write FOnOpen;
{ Listener stopped. This means that we're no longer waiting on
a specific port for incomming connections. This event will be
triggered if the call to "Disconnect" was succesfull.
@longcode(#
NOTE: OnListenStop allways comes in pair with proior OnListenStart.
OnListenStop will not be triggered for server components
where OnListenStart was not triggered before.
#) }
property OnListenStop:TRtcNotifyEvent read FOnClose write FOnClose;
{ This event will be called when our listener closes,
without us calling the 'Disconnect' method. }
property OnListenLost:TRtcNotifyEvent read FOnListenLost write FOnListenLost;
{ This event will be called when listener can not start because of an error. }
property OnListenError:TRtcErrorEvent read FOnListenError write FOnListenError;
{ This event will be triggered just before starting a new listening
attempt, when a listener had to be restarted (listener killed by OS). }
property OnRestart:TRtcNotifyEvent read FOnRestart write FOnRestart;
end;
{ --- TRtcClient --- }
{ @Abstract(Reconnect parameters for TRtcClient components)
@name is tightly coupled with @Link(TRtcClient) component.
It encapsulates the parameters used to define how a client
connection should act when a connection can not be
established, or when connection gets lost. }
TRtcReconnectParam = class(TPersistent)
private
FConnectError:boolean;
FConnectFail:boolean;
FConnectLost:boolean;
FWait:integer;
public
{ @class will be created by TRtcClient component.
@exclude }
constructor Create;
{ @class will be destroyed by TRtcClient component.
@exclude }
destructor Destroy; override;
published
{ Set ConnectError to TRUE if you want automatic reconnect on Connect Errr. }
property ConnectError:boolean read FConnectError write FConnectError default False;
{ Set ConnectLost to TRUE if you want automatic reconnect on Connect Lost. }
property ConnectLost:boolean read FConnectLost write FConnectLost default False;
{ Set ConnectFail to TRUE if you want automatic reconnect on Connect Fail. }
property ConnectFail:boolean read FConnectFail write FConnectFail default False;
{ Wait defines how long (in seconds) component should wait before it tries to reconnect. }
property Wait:integer read FWait write FWait default 0;
end;
{ @Abstract(Basic Client-side connection component wrapper)
@name publishes methods and handles all the tasks that are common to all
Client connection components. All Client-side connection components
are indirect descendants of TRtcClient and therefor inherit
all its methods and properties. Since @name is also a direct descendant
of @Link(TRtcConnection), it also inherits all methods and properties
from @Link(TRtcConnection). For more information, check @Link(TRtcConnection). }
TRtcClient = class(TRtcConnection)
private
FReconnectOn:TRtcReconnectParam;
FOnConnectError:TRtcErrorEvent;
FOnConnectFail:TRtcNotifyEvent;
FOnConnectLost:TRtcNotifyEvent;
FOnReconnect:TRtcNotifyEvent;
protected
// @exclude
function isConnectionRequired:boolean; virtual;
// @exclude
procedure SetMultiThread(const Value: boolean); override;
{ This is a ConnectionOpening trigger,
ready to be mapped to a connection provider.
Will trigger an exception if connection may not be opened (for any reason).
@exclude }
procedure TriggerConnectionOpening(Force:boolean=False); virtual;
{ This is a ConnectionClosing trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerConnectionClosing; virtual;
{ This is a ReadyToRelease trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerReadyToRelease; override;
{ This is a ConnectFail trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerConnectFail; virtual;
// @exclude
procedure CallConnectFail; virtual;
{ This is a ConnectLost trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerConnectLost; virtual;
// @exclude
procedure CallConnectLost; virtual;
{ This is a ConnectError trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerConnectError(E:Exception); virtual;
// @exclude
procedure CallConnectError(E:Exception); virtual;
{ This is a Reconnect trigger,
ready to be mapped to a connection provider.
@exclude }
procedure TriggerReconnect; virtual;
// @exclude
procedure CallReconnect; virtual;
{ @name sets all parameters for the connection provider,
introduced by the @Link(TRtcClient) connection component.
It calls 'inherited' to set inherited properties.
@exclude }
procedure SetParams; override;
{ @name sets all triggers for the connection provider,
introduced by the @Link(TRtcClient) connection component.
It calls 'inherited' to set inherited triggers.
@exclude }
procedure SetTriggers; override;
{ @name clears all triggers for the connection provider,
introduced by the @Link(TRtcClient) connection component.
It calls 'inherited' to clear inherited triggers.
@exclude }
procedure ClearTriggers; override;
{ @name is a trigger, implementing a Timer event to
reconnect the client connection.
@exclude }
procedure OnReconnect_Timer; virtual;
{ Returns TRUE if this connection is connected or currently connecting. }
function isConnecting:boolean; virtual;
public
{ When creating TRtcClient components at runtime,
never use Create(). Always use the NEW class function,
implemented by all RTC connection components. }
constructor Create(AOwner: TComponent); override;
{ To destroy connection component created at runtime,
never use Free or Destroy. Always use the @Link(TRtcConnection.Release) method. }
destructor Destroy; override;
{ Connect to @Link(TRtcConnection.ServerAddr) on @Link(TRtcConnection.ServerPort) (a Listener has to be waiting there).
Before you start sending data out, wait for the @Link(TRtcConnection.OnConnect) event.
If there will be something to read from the connection, the @Link(TRtcConnection.OnDataReceived)
event will be triggered. Do not call @Link(TRtcConnection.Read) from anywhere else that
the @Link(TRtcConnection.OnDataReceived) event.
@html(<br><br>)
You can use the 'Force' parameter to force a connection attempt
even if the connection count limit has been reached.
@html(<br><br>)
If the host address can not be resolved, port is invalid or something
else is wrong with connecion data, and you have defined the 'OnConnectError' event,
then the 'OnConnectError' event will be triggered, but there will be NO EXCEPTIONS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -