UDP Client

Send and receive UDP datagrams from Delphi/C++Builder. Unicast, broadcast and multicast support, plus the optional reliable-UDP overlay used by the WebRTC stack.

TsgcUDPClient

High-performance UDP datagram client — the foundation under STUN, TURN, ICE, RTCPeerConnection and any custom UDP protocol you write.

Component class

TsgcUDPClient

Protocol

UDP (RFC 768)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Drop the component, send packets

Set Host / Port, Active := True, then call WriteData with the bytes you want to send. Inbound datagrams arrive on OnMessage.

uses
  sgcP2P;

var
  UDP: TsgcUDPClient;
begin
  UDP := TsgcUDPClient.Create(nil);
  UDP.Host := '127.0.0.1';
  UDP.Port := 4000;

  UDP.OnMessage := procedure(Connection: TsgcUDPConnection;
    const aText: string)
  begin
    Memo1.Lines.Add(aText);
  end;

  UDP.Active := True;
  UDP.WriteData('hello over UDP');
end;
// uses: sgcP2P
TsgcUDPClient *UDP = new TsgcUDPClient(this);
UDP->Host = "127.0.0.1";
UDP->Port = 4000;

UDP->Active = true;
UDP->WriteData("hello over UDP");

What's inside

A thin, predictable UDP socket layer used as the transport for STUN / TURN / ICE / WebRTC and any custom datagram protocol.

Unicast send/receive

WriteData(text) and WriteData(bytes) queue an outbound datagram. OnMessage / OnBinary deliver inbound packets with the originating endpoint.

Broadcast

Set Broadcast := True to enable broadcast addressing. WriteData to 255.255.255.255 reaches every host on the local subnet.

Multicast

JoinMulticastGroup(addr) / LeaveMulticastGroup(addr) attach the socket to one or more multicast groups; outbound packets to those addresses fan out to every subscribed peer.

Local binding

Set LocalPort / LocalHost to fix the source endpoint — required for STUN/TURN allocations and for NAT traversal symmetry.

IPv4 / IPv6

IP version is auto-detected from the host literal. Configure IPVersion explicitly when you need to force AAAA / IPv6 paths.

Used under the P2P stack

Every higher P2P component (TsgcSTUNClient, TsgcTURNClient, TsgcICEClient, TsgcRTCPeerConnection) uses this client internally as its UDP transport.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcUDPClient Full property, method and event reference for this component.
Demo Project — Demos\35.P2P\01.UDP_Server_Client Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Send UDP from Delphi?

Download the free trial and add UDP datagram support to your Delphi applications.