SkillAgentSearch skills...

DzSocket

Delphi Client/Server components to communicate using TCP Socket Asynchronous easily

Install / Use

/learn @digao-dalpiaz/DzSocket
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

DzSocket

Delphi TCP Socket Client and Server communication with Unicode support

Delphi Supported Versions Platforms Auto Install VCL and FMX Unicode support

ko-fi

Demo Example

What's New

  • 09/12/2021 (Version 3.1)

    • Delphi 11 auto-install support.
<details> <summary>Click here to view the entire changelog</summary>
  • 05/25/2021 (Version 3.0)

    • Redesigned data sending and receiving, using stream and UTF8 encoding, and avoiding receiving overload by using TCriticalSection.
    • Improved error handling on socket message receiving.
    • Included automatic reconnection support.
  • 03/13/2021 (Version 2.6)

    • Removed CompInstall.exe from component sources due to AV false positive warning (now you can get it directly from CompInstall repository).
  • 02/01/2021 (Version 2.5)

    • Removed Delphi XE2 from the list of environments as it was never possible to compile in this version.
    • Fixed XE6 conditional directive about JSON, because was incorrectly pointing to XE5.
  • 12/18/2020 (Version 2.4)

    • Updated Component Installer app (Fixed call to rsvars.bat when Delphi is installed in a path containing spaces characters).
  • 11/28/2020

    • Included new FMX chat demo application.
  • 10/31/2020 (Version 2.3)

    • Included Delphi 10.4 auto-install support.
  • 10/27/2020 (Version 2.2)

    • Fixed previous Delphi versions (at least on XE2, XE3, XE4 and XE5) package tag. It was causing package compilation error.
    • Fixed to use JSON unit only when Delphi XE6 or higher.
  • 10/26/2020 (Version 2.1)

    • Updated CompInstall to version 2.0 (now supports GitHub auto-update)
  • 10/09/2020

    • Changed disregard treatment to occur in Send method instead SendAll / SendAllEx (internally call Send method anyway).
  • 10/06/2020

    • Implemented treatment to disregard client connection in SendAll / SendAllEx methods from the moment of their disconnection event.
  • 09/24/2020

    • Included empty string validation on DataToArray to avoid JSON conversion error.
  • 07/16/2020

    • New authentication/authorization support!!!
    • Array data send conversion methods.
    • Removed SendAllOnlyWithData property.
  • 07/12/2020

    • Increase reading speed by not change string variable multiple times.
  • 05/03/2020

    • Updated CompInstall to version 1.2
  • 04/19/2020

    • Fixed Client Error event behavior to occur after internal operations. Possible behavior changing. Check issue #3. :warning:
    • Implemented SendAllOnlyWithData public property.
    • Fixed connection Lookup error to bring OnDisconnect with WasConnected=False.
  • 03/31/2019

    • Include support to Unicode characters on commands and messages text
</details>

Description

These components allows you to establish TCP Socket asynchronous communication between computers on LAN network or the Internet.

The DzTCPServer and DzTCPClient uses TClientSocket and TServerSocket of System.Win.ScktComp unit. These classes are available on Delphi, but is a little difficult to implement because you need to read and write buffer data and there are not many resources available.

The usage is very simple. You gonna need to drop the server component on server-side app and the client component on client-side app and start coding the command messages.

You can do a lot of stuff, like chat app, remote commands app, remote monitoring app, and even send streams like files. The sky is the limit. :wink:

Delphi native component differences

  • Cache structure: When you are using Delphi native socket component, If you send multiple messages simultaneously, the recipient may receive the messages grouped or divided, so you need always to deal with this problem. DzSocket controls socket messages automatically, so you always receive one event per message.

  • KeepAlive: When you establish a socket connection, if one side of connection is lost, the other side will not be communicated until a new message attempts to be send. So you can implement a manual ping, but this will give a lot of unnecessary work. DzSocket has the KeepAlive resource, enabling network native keep-alive protocol.

  • Commands: The native socket allows you to send string segment, but if you want to send commands and identify this commands in the other side of the connection, you will need to manually implement this. With DzSocket, you have a Char command always available. Ready, fast and easy.

  • Auto Free Data Objects on Server: The Client object list available on Server component has a Pointer property, allowing you to store information about the client connection, usually using a object. With DzSocket, you don't need to worry about this object destruction. You just need to enable a property to take care of these objects.

  • Enumerator: The native Server component does not have a enumerator to iterate Client List connections. Using DzSocket, you can simply do a for .. in directly on Server component, iterating client list connections.

  • SendAll: Easily send command to all clients. Besides that, you can use SendAllEx to send command to all clients except a specific client connection.

  • Connection Monitor: There is a Connection Lost event allowing you to know when the connection was closed without the client request.

  • Unicode support: The Delphi native component does not support sending messages using Unicode strings, unless you write your own code to convert data stream on the both sides. This is really boring and takes time. Using DzSocket you can simply send message text using directly method parameter as string type, so Delphi will consider Unicode characters as WideString by default.

  • Login control: You can control client authentication/authorization by using simple events and you can send extra data information to control client access to the server.

  • Auto Reconnection: The client component can auto-reconnect to the server when the connection is lost, just by enabling a property.

And much more! :wink:

Installing

Auto install

  1. Download Component Installer from: https://github.com/digao-dalpiaz/CompInstall/releases/latest
  2. Put CompInstall.exe into the component repository sources folder.
  3. Close Delphi IDE and run CompInstall.exe app.

Manual install

  1. Open DzSocket package in Delphi.
  2. Ensure Win32 Platform and Release config are selected.
  3. Then Build and Install.
  4. If you want to use Win64 platform, select this platform and Build again.
  5. Add sub-path Win32\Release to the Library paths at Tools\Options using 32-bit option, and if you have compiled to 64 bit platform, add sub-path Win64\Release using 64-bit option.

Supports Delphi XE3..Delphi 11

Server Component

Server Properties

AutoFreeObjs: Boolean (public) = If you are using Data property of client sockets on server to assign objects, you may enable this option, so the component will take care of object destruction when client socket ends. Remember, if this option is enabled and the Data property of socket is assigned, the component will presume always Data as object.

EnumeratorOnlyAuth: Boolean (public) = When using component enumerator for in, by-pass clients non authenticated yet.

KeepAlive: Boolean = Allow enable KeepAlive socket native resource. This will send a keep-alive signal using KeepAliveInterval property.

KeepAliveInterval: Integer = Specifies the KeepAlive interval in milliseconds (default 15000 / 15 seconds).

Port: Word = Specifies the Server listen TCP Port. This property is required to start server socket.

Connection[Index: Integer]: TDzSocket (public) = Returns the TDzSocket client connection object by Index.

Count: Integer (public) = Returns the client connections list count.

Server Events

procedure OnClientConnect(Sender: TObject; Socket: TDzSocket);

This event is triggered when a client connects to the server. The Socket parameter is the client socket.

procedure OnClientDisconnect(Sender: TObject; Socket: TDzSocket);

This event is triggered when a client disconnects from the server. The Socket parameter is the client socket.

procedure OnClientError(Sender: TObject; Socket: TDzSocket;
  const Event: TErrorEvent; const ErrorCode: Integer; const ErrorMsg: string);

This event is triggered when occurs an error on a client connection. The Socket parameter is the client socket.

procedure OnClientRead(Sender: TObject; Socket: TDzSocket;
  const Cmd: Char; const A: string);

This event is triggered when a client sends a message to the server. The Socket parameter is the client socket.

procedure OnClientLoginCheck(Sender: TObject; Socket: TDzSocket; var Accept: Boolean;
  const RequestData: String; var ResponseData: String);

This event is triggered when a client has just connected to the server. If at the client side, the OnLoginRequest is handled, the data information sent will be receiver here into the RequestData parameter. You can change the Accept parameter (initial default value is True) to accept or reject client connection. Besides that, you can use the ResponseData parameter to send to the client so

Related Skills

View on GitHub
GitHub Stars70
CategoryDevelopment
Updated4h ago
Forks16

Languages

Pascal

Security Score

100/100

Audited on Mar 27, 2026

No findings