UDP Server
Listen for UDP datagrams on a port and dispatch each one to your application. The same engine that powers TsgcSTUNServer and TsgcTURNServer.
Listen for UDP datagrams on a port and dispatch each one to your application. The same engine that powers TsgcSTUNServer and TsgcTURNServer.
High-performance UDP listener — bind to a port, receive datagrams from any peer, reply to specific endpoints, scale across cores via worker threads.
TsgcUDPServer
Windows, macOS, Linux, iOS, Android
Professional / Enterprise
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;
A multi-threaded UDP listener that dispatches each datagram to a worker pool and exposes a TsgcUDPConnection for the reply path.
One bound socket handles datagrams from any number of remote endpoints. Each OnMessage fires with a TsgcUDPConnection identifying the originating PeerIP / PeerPort.
Connection.WriteData sends a datagram back to the originating peer using the same socket — no extra outbound binding needed.
A worker pool processes inbound packets — configure via WorkerCount if your handler does heavy work. The receive thread is never blocked.
Supports IPv4-only, IPv6-only or dual-stack binding via IPVersion. Multicast group joins are exposed through JoinMulticastGroup.
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.
Set DontFragment := True on outbound writes — useful for path-MTU probing in custom protocols.
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. | Open | |
| Demo Project — Demos\35.P2P\01.UDP_Server_Client Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |