Changeset 464


Ignore:
Timestamp:
May 19, 2014, 12:27:14 AM (11 years ago)
Author:
chronos
Message:
  • Added: Basic TTCPClient class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Network/CoolWeb/Network/UTCPServer.pas

    r311 r464  
    6767  end;
    6868
     69  { TTCPServer }
     70
     71  TTCPClient = class
     72  private
     73    FActive: Boolean;
     74    FSocket: TTCPBlockSocket;
     75    procedure SetActive(AValue: Boolean);
     76  public
     77    Address: string;
     78    Port: Word;
     79    constructor Create;
     80    destructor Destroy; override;
     81    property Socket: TTCPBlockSocket read FSocket;
     82    property Active: Boolean read FActive write SetActive;
     83  end;
     84
    6985implementation
     86
     87{ TTCPClient }
     88
     89procedure TTCPClient.SetActive(AValue: Boolean);
     90begin
     91  if AValue and not FActive then begin
     92    with FSocket do begin
     93      CreateSocket;
     94      Connect(Address, IntToStr(Port));
     95      if LastError <> 0 then raise Exception.Create('Socket connect error');
     96    end;
     97  end else
     98  if not AValue and FActive then begin
     99    with FSocket do begin
     100      CloseSocket;
     101    end;
     102  end;
     103  FActive := AValue;
     104end;
     105
     106constructor TTCPClient.Create;
     107begin
     108  FSocket := TTCPBlockSocket.Create;
     109  Address := '0.0.0.0';
     110  Port := 80;
     111end;
     112
     113destructor TTCPClient.Destroy;
     114begin
     115  Active := False;
     116  FSocket.Free;
     117  inherited Destroy;
     118end;
    70119
    71120{ TTCPServer }
Note: See TracChangeset for help on using the changeset viewer.