Skip to content
Projects

winddriver/Delphi-Cross-Socket

View on GitHub

About

Cross-platform socket library for Delphi

Developer Tools

How these counts are measured

Measured star growth

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.en.md

Original

Delphi Cross Platform Socket Communication Library

Author: WiNDDRiVER([email protected])

中文


Update list

2025.04.10

  • ICrossHttpClient supports binding of local ports (LocalPort property)
  • ICrossSslConnection supports getting ssl details (GetSSLInfo method)
  • Some other small features improvements and corrections

2023.09.18

  • Supports FPC 3.3.1
  • Supports OpenSSL 3.x
  • Added HTTP client ICrossHttpClient (Supports sending data compressed with gzip/deflate)
  • Added WebSocket client ICrossWebSocket
  • The HTTP server supports receiving gzip/deflate compressed data
  • Partial code refactoring
  • Some minor bug fixes

2020.07.07

  • ICrossHttpServer and ICrossWebSocketServer support both http and https

    Thanks to xlnron for his help

2019.02.17

  • Fix the problem of memory leakage caused by TIoEventThread

    thank viniciusfbb for finding and fixing the problem

  • Fix memory leak caused by [weak]

    when used with a third-party memory management library, there will be a memory leak. robertodellapasqua found the problem and pony5551 finally found the cause of the problem. Thank you very much! This should be a defect in Delphi's [weak] internal implementation. The problem was solved after replacing [weak] with [unsafe]

2019.01.15

  • increase mbedtls support

    • mbedtls enabling method: turn on __CROSS_SSL__ and __MBED_TLS__ in the engineering compilation option, and add the directory under MbedObj to the Library path of the corresponding platform
    • mbedtls support is not stable at present, please do not use it in production environment

    2017.08.22

    • code refactoring, with many modifications, see source code for details
    • Several new interface have been added. See demos for usage
      • ICrossSocket
      • ICrossSslSocket
      • ICrossServer
      • ICrossSslServer

TLS / mTLS configuration

  • The existing non-verifying TLS behavior remains the default.
  • Before enabling peer verification, call AddCACertificate (repeated calls and PEM bundles are supported), then set VerifyPeer := True.
  • An mTLS server must set its certificate and private key. An mTLS client must also set its own certificate and private key before Connect or the first HTTPS request.
  • A verifying client checks both the server certificate chain and its DNS host name. System root stores are not loaded by this initial implementation.
  • Certificates, private keys, CAs, VerifyPeer, and cipher suites cannot be changed after the first SSL connection is created.

TLS 1.2 / TLS 1.3 cipher suites

The OpenSSL backend exposes two separate methods on ICrossSslSocket, for both clients and servers:

The minimum protocol version is TLS 1.2 by default; SetMinTlsVersion(tmvTls13) raises the minimum to TLS 1.3. The component leaves the maximum version to the library and system configuration. Future protocol versions still require independent compatibility validation.

LSocket.SetTls12CipherSuites('ECDHE-RSA-AES128-GCM-SHA256');
LSocket.SetTls13CipherSuites('TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384');
LSocket.SetMinTlsVersion(tmvTls13); // optional: minimum TLS 1.3
  • SetTls12CipherSuites accepts OpenSSL TLS 1.2 cipher rules. SetTls13CipherSuites accepts TLS 1.3 suite names separated by colons, in preference order.
  • New OpenSSL sockets use the public constants in Net.CrossSslSocket.Types: DEFAULT_TLS12_CIPHER_SUITES contains six ECDHE + AES-GCM/ChaCha20-Poly1305 suites for RSA/ECDSA certificates; DEFAULT_TLS13_CIPHER_SUITES contains AES-256-GCM, ChaCha20-Poly1305, and AES-128-GCM.
  • The defaults no longer include the previous HIGH expansion, CBC, finite-field DHE, or TLS 1.3 CCM/CCM_8. Endpoints requiring those suites need explicit configuration before the first SSL connection.
  • An empty string leaves the current configuration unchanged; it neither restores defaults nor disables a protocol. Pass the corresponding DEFAULT_TLSxx_CIPHER_SUITES constant to restore a suite list.
  • The lists are separate, but @SECLEVEL in TLS 1.2 rules changes the context-wide security level and can affect TLS 1.3 handshakes. Restoring a list or calling the TLS 1.3 setter does not reset that level.
  • Inputs follow native OpenSSL semantics. Unknown TLS 1.2 items may be ignored. Unknown TLS 1.3 names are rejected by OpenSSL 1.1.1 and may be ignored by 3.x. Both setters check the native result; failure raises ESslContextInvalid and invalidates the socket's entire TLS configuration. Recreate the socket after such a failure.
  • SetMinTlsVersion takes TCrossTlsMinVersion from Net.CrossSslSocket.Types: tmvTls12 (the default, never lower) or tmvTls13. The OpenSSL backend reads the minimum back from the context after setting it; a failed call or a value that did not take raises ESslContextInvalid and invalidates the socket's TLS configuration. The maximum version and both suite lists are unchanged. The mbedTLS backend defaults both client and server minimums to TLS 1.2; tmvTls12 explicitly applies that minimum and tmvTls13 is rejected as unsupported. Custom backends without this implementation reject both values. When SSL is enabled, minimum-version configuration must also finish before the first connection.
  • Finish configuration before creating SSL connections. Each setter takes the configuration lock; the pair is not an atomic transaction. SSL-disabled sockets perform no configuration. The mbedTLS backend explicitly rejects non-empty configuration for both methods.
  • Rebuild all consumers and derived interfaces, including DCU/PPU/BPL/DLL files, from the same source version after the ICrossSslSocket interface change. Mixing old and new binaries is unsupported. No configuration forwarding methods have been added to ICrossHttpClient.

See TlsCipherSuitesTests for reproducible configuration and handshake tests.

Features

  • Use different IO models for different platforms:

    • IOCP

    Windows

    • KQUEUE

    FreeBSD(MacOSX, iOS...)

    • EPOLL

    Linux(Linux, Android...)

    • Supports extremely high concurrency

      • Windows

      can run more than 100000 concurrent number, need to modify the registry to adjust the default maximum port number

      • Mac

      preliminary tests were conducted. the test environment was OSX 10.9.5 in the virtual machine. even if the limit on the number of handles in the system was modified, can only open more than 32000 concurrent connections at most, perhaps OSX Server version can support higher concurrency

    • IPv4 and IPv6 are supported at the same time.

    • Zero Memory Copy

Passed the test

  • Windows
  • OSX
  • iOS
  • Android
  • Linux

Suggested Development Environment

  • To give full play to cross-platform functions, please use Delphi 10.2 Tokyo or higher
  • The minimum requirement is to support the Delphi version of generic and anonymous functions. I am not sure from which version generic and anonymous functions are supported.
  • It is recommended to use FPC version 3.3.1 or higher

Some Test Screenshots

  • HTTP Benchmark image

  • HTTPS Benchmark image

  • HTTP Server(Linux-aarch64) image

  • HTTP Server(Linux-loongarch64) image

  • HTTP Client(Linux-aarch64) image

  • HTTP Client(Linux-loongarch64) image

  • WebSocket Server(Linux-aarch64) image

  • WebSocket Server(Linux-loongarch64) image

  • WebSocket Client(Linux-aarch64) image

  • WebSocket Client(Linux-loongarch64) image

  • HTTP(服务端为ubuntu 16.04 desktop) 20170607110011

  • HTTPS(服务端为ubuntu 16.04 desktop) 20170607142650

Explore related projects

Loading…