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

📄 iggstreamcomp.pas

📁 通信控件
💻 PAS
字号:
unit IGgStreamComp;

interface

uses
  Windows, Classes, WinSock, IGgStreamServer, IGgStreamClient;

const
  IServer_Version	 = '1.0'; //2007.12.23

type

  { TIStreamComponent }

  TIStreamComponent = class(TComponent)
  public
    function GetVersion: string;
    property Version: string read GetVersion;
  published
  end;

  { TIStreamServer }
  
  TIStreamServer = class(TIStreamComponent)
  private
    FServer: TIServer;

  protected
    function GetActive: Boolean;
    procedure SetActive(const Value: Boolean);
    function GetHost: string;
    procedure SetHost(const Value: string);
    function GetPort: Integer;
    procedure SetPort(const Value: Integer);
    function GetOnStartupNotify: TOnStartupNotify;
    procedure SetOnStartupNotify(Value: TOnStartupNotify);
    function GetOnStopNotify: TOnStopNotify;
    procedure SetOnStopNotify(Value: TOnStopNotify);

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    function SetUserInfo(NameID: string; Info: Pointer; InfoSize: Integer): Integer;
    function GetUserInfo(NameID: string; var Info: Pointer): Integer;
    function GetUsersInfo(var Infos: Pointer; Status: Integer=0): Integer;
    procedure FreeUsersInfo(Infos: Pointer);
    procedure DeleteUser(Status: Integer); overload;
    function DeleteUser(NameID: string): Boolean; overload;

  published
    property Active: Boolean read GetActive write SetActive Default False;
    property Host: string read GetHost write SetHost;
    property Port: Integer read GetPort write SetPort default DEF_SERVER_PORT;
    property OnStartupNotify: TOnStartupNotify read GetOnStartupNotify write SetOnStartupNotify;
    property OnStopNotify: TOnStopNotify read GetOnStopNotify write SetOnStopNotify;
  end;


  { TIStreamClient }

  TIStreamClient = class(TIStreamComponent)
  private
    FClient: TIClient;

  protected

    function GetActive: Boolean;
    procedure SetActive(const Value: Boolean);
    function GetServerAddress: string;
    procedure SetServerAddress(const Value: string);
    function GetServerPort: Integer;
    procedure SetServerPort(const Value: Integer);
    function GetBindAddress: string;
    procedure SetBindAddress(const Value: string);
    function GetBindPort: Integer;
    function GetOnConnectNofity: TOnConnectStatusNotify;
    procedure SetOnConnectNotify(Value: TOnConnectStatusNotify);
    function GetOnSendBufferNotify: TOnSendBufferNotify;
    procedure SetOnSendBufferNotify(Value: TOnSendBufferNotify);
    function GetOnReceiveBufferNotify: TOnReceiveBufferNotify;
    procedure SetOnReceiveBufferNotify(Value: TOnReceiveBufferNotify);

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure Open(NameID: string);
    procedure Close();
    procedure SetInfo(Info: Pointer; InfoSize: Integer);
    function GetInfo(NameID: string): Pointer;
    procedure Connect(NameID: string);
    procedure Disconnect(NameID: string);
    procedure SendBuffer(NameID: string; Buffer: Pointer; BufferSize: Integer);

  published
    property Active: Boolean read GetActive write SetActive default FALSE;
    property ServerAddress: string read GetServerAddress write SetServerAddress;
    property ServerPort: Integer read GetServerPort write SetServerPort;
    property BindAddress: string read GetBindAddress write SetBindAddress;
    property BindPort: Integer read GetBindPort;
    property OnConnectStatusNotify: TOnConnectStatusNotify read GetOnConnectNofity write SetOnConnectNotify;
    property OnSendBufferNotify: TOnSendBufferNotify read GetOnSendBufferNotify write SetOnSendBufferNotify;
    property OnReceiveBufferNotify: TOnReceiveBufferNotify read GetOnReceiveBufferNotify write SetOnReceiveBufferNotify;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TIStreamServer]);
end;

 { TIStreamComponent }

function TIStreamComponent.GetVersion: string;
begin
  Result := IServer_Version;
end;


 { TIStreamServer }

constructor TIStreamServer.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FServer := TIServer.Create;
end;
destructor TIStreamServer.Destroy;
begin
  try
    if Assigned(FServer) then FServer.Free;
  except  end;
  inherited Destroy;
end;
function TIStreamServer.GetActive: Boolean;
begin
  Result := FServer.Active;
end;
procedure TIStreamServer.SetActive(const Value: Boolean);
begin
  FServer.Active := Value;
end;
function TIStreamServer.GetHost: string;
begin
  Result := FServer.GetBindAddress;
end;
procedure TIStreamServer.SetHost(const Value: string);
begin
  FServer.SetBindAddress(Value);
end;
function TIStreamServer.GetPort: Integer;
begin
  Result := FServer.GetBindPort;
end;
procedure TIStreamServer.SetPort(const Value: Integer);
begin
  FServer.SetBindPort(Value);
end;
function TIStreamServer.SetUserInfo(NameID: string; Info: Pointer; InfoSize: Integer): Integer;
begin
  if Active then
    Result := FServer.SetUserInfo(NameID, Info, InfoSize);
end;
function TIStreamServer.GetUserInfo(NameID: string; var Info: Pointer): Integer;
begin
  if Active then
    Result := FServer.GetUserInfo(NameID, Info);
end;
function TIStreamServer.GetUsersInfo(var Infos: Pointer; Status: Integer): Integer;
begin
  if Active then
    Result := FServer.GetUsersInfo(Infos, Status);
end;
procedure TIStreamServer.FreeUsersInfo(Infos: Pointer);
begin
  if Active then
    FServer.FreeUsersInfo(Infos);
end;
procedure TIStreamServer.DeleteUser(Status: Integer);
begin
  if Active then
    FServer.DeleteUser(Status);
end;
function TIStreamServer.DeleteUser(NameID: string): Boolean;
begin
  Result := FALSE;
  if Active then
    Result := FServer.DeleteUser(NameID);
end;
function TIStreamServer.GetOnStartupNotify: TOnStartupNotify;
begin
  Result := FServer.OnStartupNotify;
end;
procedure TIStreamServer.SetOnStartupNotify(Value: TOnStartupNotify);
begin
  if Assigned(Value) then
    FServer.OnStartupNotify := Value;
end;
function TIStreamServer.GetOnStopNotify: TOnStopNotify;
begin
  Result := FServer.OnStopNotify;
end;
procedure TIStreamServer.SetOnStopNotify(Value: TOnStopNotify);
begin
  if Assigned(Value) then
    FServer.OnStopNotify := Value;
end;

  { TIStreamClient }

constructor TIStreamClient.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FClient := TIClient.Create;
end;
destructor TIStreamClient.Destroy;
begin
  try
    if Assigned(FClient) then FClient.Free;
  except  end;
  inherited Destroy;
end;
function TIStreamClient.GetActive: Boolean;
begin
  Result := FClient.Active;
end;
procedure TIStreamClient.SetActive(const Value: Boolean);
begin
  FClient.Active := Value;
end;
function TIStreamClient.GetServerAddress: string;
begin
  Result := FClient.GetServerAddress;
end;
procedure TIStreamClient.SetServerAddress(const Value: string);
begin
  FClient.SetServerAddress(Value);
end;
function TIStreamClient.GetServerPort: Integer;
begin
  Result := FClient.GetServerPort;
end;
procedure TIStreamClient.SetServerPort(const Value: Integer);
begin
  FClient.SetServerPort(Value);
end;
function TIStreamClient.GetBindAddress: string;
begin
  Result := FClient.GetBindAddress;
end;
procedure TIStreamClient.SetBindAddress(const Value: string);
begin
  FClient.SetBindAddress(Value);
end;
function TIStreamClient.GetBindPort: Integer;
begin
  Result := FClient.GetBindPort;
end;
procedure TIStreamClient.Open(NameID: string);
begin
  FClient.Open(NameID, FClient.GetServerAddress, FClient.GetBindAddress);
end;
procedure TIStreamClient.Close;
begin
 FClient.Close();
end;
procedure TIStreamClient.SetInfo(Info: Pointer; InfoSize: Integer);
begin
  FCLient.SetOwnerInfo(Info, InfoSize);
end;
function TIStreamClient.GetInfo(NameID: string): Pointer;
begin
  Result := FClient.GetUserInfo(NameID);
end;
procedure TIStreamClient.Connect(NameID: string);
begin
  FClient.Connect(NameID);
end;
procedure TIStreamClient.Disconnect(NameID: string);
begin
  FClient.Disconnect(NameID);
end;
function TIStreamClient.GetOnConnectNofity: TOnConnectStatusNotify;
begin
  Result := FClient.OnConnectNotify;
end;
procedure TIStreamClient.SetOnConnectNotify(Value: TOnConnectStatusNotify);
begin
  if Assigned(Value) then
    FClient.OnConnectNotify := Value;
end;
function TIStreamClient.GetOnSendBufferNotify: TOnSendBufferNotify;
begin
  Result := FClient.OnSendNotify;
end;
procedure TIStreamClient.SetOnSendBufferNotify(Value: TOnSendBufferNotify);
begin
  if Assigned(Value) then
    FClient.OnSendNotify := Value;
end;
function TIStreamClient.GetOnReceiveBufferNotify: TOnReceiveBufferNotify;
begin
  Result := FClient.OnReceiveNotify;
end;
procedure TIStreamClient.SetOnReceiveBufferNotify(Value: TOnReceiveBufferNotify);
begin
  if Assigned(Value) then
    FClient.OnReceiveNotify := Value;
end;
procedure TIStreamClient.SendBuffer(NameID: string; Buffer: Pointer; BufferSize: Integer);
begin
  FClient.SendBuffer(NameID, Buffer, BufferSize);
end;

end.

⌨️ 快捷键说明

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