Download Now

    Reference TSocket

    Declared in Codebot.Networking.pas on line 86

    TSocket provide a simple object oriented interface to network sockets
      TSocket = class(TObject)
      public
        { Create a new socket }
        constructor Create; overload;
        { Create an incoming connection for a server socket }
        constructor Create(Server: TSocket); overload;
        { Close and destroy the socket }
        destructor Destroy; override;
        { Close the socket }
        procedure Close;
        { Connect to an address converting the state to a client }
        function Connect(const Address: TAddressName; Port: Word): Boolean;
        { Listen on address and port converting the state to a server }
        function Listen(const Address: TAddressName; Port: Word): Boolean; overload;
        { Listen on port converting the state to a server }
        function Listen(Port: Word): Boolean; overload;
        { While listening wait to accept an incoming connection }
        function Accept(Socket: TSocket): Boolean;
        { Read from a client or remote socket to a buffer }
        function Read(var Buffer; BufferSize: LongWord): Integer; overload;
        { Read from a client or remote socket to text }
        function Read(out Text: string; BufferSize: LongWord = $10000): Integer; overload;
        { Write a buffer to a client or remote socket }
        function Write(var Buffer; BufferSize: LongWord): Integer; overload;
        { Write text to a client or remote socket }
        function Write(const Text: string): Integer; overload;
        { Write all bytes in a buffer to a client or remote socket }
        function WriteAll(var Buffer; BufferSize: LongWord): Boolean; overload;
        { Write all text to a client or remote socket }
        function WriteText(const Text: string; Task: IAsyncTask = nil): Boolean; overload;
        { Write the contents of a file to a client or remote socket }
        function WriteFile(const FileName: string; Task: IAsyncTask = nil): Boolean;
        { Write a stream to a client or remote socket }
        function WriteStream(Stream: TStream; Task: IAsyncTask = nil): Boolean;
        { The address of socket }
        property Address: TAddressName read GetAddress;
        { When blocking is true, read and write operations wait }
        property Blocking: Boolean read FBlocking write SetBlocking;
        { The kind of the socket to create }
        property Kind: TSocketKind read FKind write FKind;
        { The port of the socket }
        property Port: Word read FPort;
        { The server socket from which a remote socket was accepted through }
        property Server: TSocket read FServer;
        { When secure is true socket communication will be routed through an SSL
          library }
        property Secure: Boolean read FSecure write SetSecure;
        { The underlying socket state }
        property State: TSocketState read FState;
        { Optional timeout period in milliseconds }
        property Timeout: LongWord read FTimeout write FTimeout;
        { Connected is true when a socket is valid and active }
        property Connected: Boolean read GetConnected;
      end;

    See also

    IAsyncTask in Codebot.System.pas