⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtcconn.pas

📁 Delphi快速开发Web Server
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    property ReadCount:int64 read FReadCount;
    { Total number of bytes sent to the other side (Peer/Remote) through this connection. }
    property WriteCount:int64 read FWriteCount;

    { This property will be set to TRUE if the connection was established,
      even though our connection limit was reached (or over the limit).
      @html(<br><br>)

      You can check the number of total conncetions open using the
      @Link(TotalConnectionCount) function. If you find this connection
      should stay open (even though the limit was reached when it connected),
      change this property to FALSE, to handle it like any other connection.
      @html(<br><br>)

      Note: This property is not being used by any TRtcConnection component
      or its descendants. It is only intended for your use. Even if
      the overLimit property is TRUE, it will not affect this connection's behavior. }
    property OverLimit:boolean read FOverLimit write FOverLimit;

    { Check current connection state.
      There is no real need to use this property to check your connection state,
      since events will be triggered when the state changes. }
    property State:TRtcConnectionState read GetState;

    { Additional connection component information.
      @html(<br><br>)

      You can use this property as you see fit.
      The only purpose of the Info property is to give
      the component user ways to store additional
      information about this conncetion inside the
      connection component itself, without having to
      create and maintain separate data structures. }
    property Info:TRtcInfo read FInfo;

  published

    { RealThinClient SDK Version (for information only) }
    property Version_SDK:string read GetVersionSDK write SetVersionSDK stored False;

    { Set the @name property to @True if you want your connection to use the
      Thread pooling mechanism, which is integrated into the RealThinClient
      library and can be used by all RTC connection components. To find out what
      more you need to keep in mind when working in multithreaded mode, check
      the @Link(TRtcConnection) description.
      @html(<br><br>)

      NOTE: This property is read only before you call 'Listen' for the server component
      or 'Connect' for the client component. Changing this property when a connection
      is open will have no effect on the component, until the next time you
      start the listener or open a new connection.
      @html(<br><br>)

      WARNING: To safely use your components in MultiThreaded mode, also check
      the Descriptions for @Link(TRtcConnection), @Link(Sync), @Link(inMainThread),
      @Link(inThread) and @Link(PostJob). }
    property MultiThreaded:boolean read FMultiThread write SetMultiThread default False;

    { You can set all timeout parameters for the client connection component or
      default timeout periods for all client connections of the server connection component
      using this property. Check @Link(TRtcTimeout) for more information. }
    property Timeout:TRtcTimeout read FTimeout write FTimeout;

    { Server Address to connect to for the Client,
      Listening address (Bind) for the Server (leave empty to listen on all network cards). }
    property ServerAddr:string read FAddr write FAddr;

    { Port on the Host to connect to for the Client,
      Listening Port (Bind) for the Server (never leave empty). }
    property ServerPort:string read FPort write FPort;

    { This event will be called when a new connection is waiting to be
      initialized. This is still BEFORE a connection is ready to read/send data. }
    property OnConnecting:TRtcNotifyEvent read FOnConnecting write FOnConnecting;

    { This event will be called when a succesful connection is being closed. }
    property OnDisconnecting:TRtcNotifyEvent read FOnDisconnecting write FOnDisconnecting;

    { This event will be called after a new connection
      has been succesfully established and is ready to be used.
      The event triggered will receive the client connection object as parameter.

      @html(<br><br>)
      * 1) If this was a client connection on which you called 'Connect' to
        attempt a new connection to a server, this event handler will
        be the first event to trigger after 'OnConnecting' and will
        receive the current connection object as parameter, only if the connection
        to the server was succesfull. If server was not available, 'OnConnectFail'
        event will be triggered instead. Also, in case of failure, the 'OnDisconnect'
        event will NOT be triggered.

      @html(<br><br>)
      * 2) If this was a listening connection (server), this event
        handler will receive a new connection object as parameter
        and be called directly after the 'OnClientConnect' and
        'OnConnecting' events. In case needed, you can change all the
        actual events to be triggered for every client connection from
        the 'OnClientConnect' event handler. But, it is not advisable
        to do so. It is better to have 1 event handler for all client connections
        that belong to a specific server and use the 'Sender' parameter to
        distinguish between different clients. }
    property OnConnect:TRtcNotifyEvent read FOnConnect write FOnConnect;

    { This event will be called when a prior working connection (for which you
      have allready received the @Link(OnConnect) event) just got disconnected,
      by either side:
      @html(<br>)
      1.) You closed it by calling @Link(Disconnect), or
      @html(<br>)
      2.) the other side closed it, or
      @html(<br>)
      3.) the connection simply colapsed. }
    property OnDisconnect:TRtcNotifyEvent read FOnDisconnect write FOnDisconnect;

    { This event is used to process exceptions that happen in the background,
      for example while sending data from buffer to the other side.
      @html(<br><br>)

      Normaly, no exceptions should happen in the background.
      If an exception happens in the background and you set the event handler
      for the OnException event, you would receive the exception object,
      so you can handle it if needed (for example, write it to a Log file).
      @html(<br><br>)

      If there is no handler for this event, background exceptions will be ignored. }
    property OnException:TRtcErrorEvent read FOnException write FOnException;

    end;

{ --- TRtcServer --- }

  { @Abstract(Restart Parameters for TRtcServer components)

    @name is tightly coupled with @Link(TRtcServer) component.
    It encapsulates the parameters used to define how a server listener
    should behave when there is a problem with the listening connection. }
  TRtcRestartParam = class(TPersistent)
  private
    FListenLost:boolean;
    FListenError:boolean;
    FWait:integer;

  public
    { Will be created by TRtcServer component.
      @exclude }
    constructor Create;
    { Will be destroyed by TRtcServer component-
      @exclude }
    destructor Destroy; override;

  published
    { Set ListenLost to TRUE if you want a restart listener on Listener Lost
        (listener closed by the system). }
    property ListenLost:boolean read FListenLost write FListenLost default False;

    { Set ListenError to TRUE if you want a restart listener on Listener Error
        (listener could not be started). }
    property ListenError:boolean read FListenError write FListenError default False;

    { Wait defines how long (in second) component should wait before it tries to restart the listener. }
    property Wait:integer read FWait write FWait default 0;
    end;

  { @Abstract(Basic Server-side connection component wrapper)

    @name publishes methods and handles all the tasks that are common to all
    Server connection components. All Server-side connection components
    are indirect descendants of TRtcServer 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).
    @html(<br><br>)

    All @Link(TRtcServer) descendant components automatically create and
    initialize a separate object (same type as the Server component) for
    every accepted Client connection. It also automatically releases the
    same object (which it created) when the client connection closes.
    This means that you will have a separate object for every client connection,
    without having to create, maintain or release it. All properties and events
    which you have defined for the TRtcServer component will be automatically
    copied into the new component, so that you do not have to do any special
    initialization to work with the connection object.
    @html(<br><br>)

    The components created automatically for each new accepted client connection
    will be of the same type as the main Server listener component. For example,
    if you created a @Link(TRtcTcpServer) component, set its properties and
    called @Link(TRtcServer.Listen), you will have access to a copy of that
    @Link(TRtcTcpServer) component, which will start its own new life from
    the second the connection is accepted by the underlying connection provider.
    @html(<br><br>)

    All events which you defined for the lisneter component, will automatically
    be copied to the new client connection component. Remember that this is
    NOT the @Link(TRtcClient) descendant component, it is a new @Link(TRtcServer)
    component, but its @Link(TRtcServer.isClient) function will return TRUE and
    @Link(TRtcServer.isListening) will return FALSE, which is a complete oposite
    to the results of same function calls on the listening server component.
    @html(<br><br>)

    ALL EVENTS for client connection components will only be called with
    the client connection components as parameter, rather than the Server
    listener component. In fact, only the 'OnListen...' events and the
    'OnRestart' event are being called with the Server listener component
    as the 'Sender' parameter. All the other events are only used by the
    connection components which are created for client connections by the
    server connection component. }
  TRtcServer = class(TRtcConnection)
  private
    FClientConnectTriggered:boolean;

    FRestartOn:TRtcRestartParam;

    FOnClientConnect:TRtcNotifyEvent;
    FOnClientDisconnect:TRtcNotifyEvent;

    FOnOpen:TRtcNotifyEvent;
    FOnClose:TRtcNotifyEvent;

    FOnListenLost:TRtcNotifyEvent;
    FOnListenError:TRtcErrorEvent;
    FOnRestart:TRtcNotifyEvent;

    procedure CallConnectionAccepting;

  protected

    // @exclude
    procedure SetMultiThread(const Value: boolean); override;

    { Called by @Link(TRtcConnection) to copy values from 'Dup' connection
     (Server connection in most cases) to this one.
      This way, the new client connection is being prepared for usage.
      @html(<br><br>)

      If you should write a new connection class inherited from @Link(TRtcConnection),
      you have to overwrite this method and implement it so that it copies
      all connection properties defined by your class from 'Dup' to this one,
      (will be a wnewly created component).
      @html(<br><br>)

      CopyFrom() is being called from connection providers after a new
      client connection has been created and needs to be prepared for usage.

      @exclude}
    procedure CopyFrom(Dup:TRtcServer); virtual;

    { This is ConnectionAccepting trigger,
      ready to be mapped to a connection provider.
      Will trigger an exception if connection may not be accepted (for any reason).
      @exclude }
    procedure TriggerConnectionAccepting; virtual;

    { This is ConnectionAccepted trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerConnectionAccepted; virtual;

    { This is ConnectionLost trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerConnectionLost; virtual;

    { This is a trigger to create a new connection provider,
      used by all server connection providers to get a fresh
      conncetion component, which they can initialize and use.
      @exclude }
    procedure TriggerNewProvider(var Provider:TObject); virtual;

    { This is a ReadyToRelease trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerReadyToRelease; override;

    { This is a ClientConnect trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerClientConnect; virtual;
    // @exclude
    procedure CallClientConnect; virtual;

    { This is a ClientDisconnect trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerClientDisconnect; virtual;
    // @exclude
    procedure CallClientDisconnect; virtual;

    { This is a ListenStart trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerListenStart; virtual;
    // @exclude
    procedure CallListenStart; virtual;

    { This is a ListenStop trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerListenStop; virtual;
    // @exclude
    procedure CallListenStop; virtual;

    { This is a ListenLost trigger,
      ready to be mapped to a connection provider.
      @exclude }
    procedure TriggerListenLost; virtual;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -