UDP Server

Listen for UDP datagrams on a port and dispatch each one to your application. The same engine that powers TsgcSTUNServer and TsgcTURNServer.

TsgcUDPServer

High-performance UDP listener — bind to a port, receive datagrams from any peer, reply to specific endpoints, scale across cores via worker threads.

Component class

TsgcUDPServer

Protocol

UDP (RFC 768)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Professional / Enterprise

Drop, listen, reply

Set Port, Active := True, then handle inbound datagrams in OnMessage and reply via Connection.WriteData — one socket, any number of remote peers.

uses
  sgcP2P;

var
  Server: TsgcUDPServer;
begin
  Server := TsgcUDPServer.Create(nil);
  Server.Port := 4000;

  Server.OnMessage := procedure(Connection: TsgcUDPConnection;
    const aText: string)
  begin
    // echo back to the originating peer
    Connection.WriteData('echo: ' + aText);
  end;

  Server.Active := True;
end;
// uses: sgcP2P
TsgcUDPServer *Server = new TsgcUDPServer(this);
Server->Port = 4000;
Server->Active = true;

What's inside

A multi-threaded UDP listener that dispatches each datagram to a worker pool and exposes a TsgcUDPConnection for the reply path.

Single-port many-peers

One bound socket handles datagrams from any number of remote endpoints. Each OnMessage fires with a TsgcUDPConnection identifying the originating PeerIP / PeerPort.

Reply path

Connection.WriteData sends a datagram back to the originating peer using the same socket — no extra outbound binding needed.

Threaded dispatch

A worker pool processes inbound packets — configure via WorkerCount if your handler does heavy work. The receive thread is never blocked.

IPv4 / IPv6 / dual-stack

Supports IPv4-only, IPv6-only or dual-stack binding via IPVersion. Multicast group joins are exposed through JoinMulticastGroup.

Used under TsgcSTUNServer / TsgcTURNServer

The STUN and TURN servers (full RFC 8489 / 8656 implementations) build on top of this component — you can do the same for any custom UDP protocol.

No-fragment hint

Set DontFragment := True on outbound writes — useful for path-MTU probing in custom protocols.

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 — TsgcUDPServer 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 Run a UDP Server?

Download the free trial and listen for UDP datagrams from Delphi.