Delphi UDP Client
Send and receive UDP datagrams from Delphi/C++Builder. IPv4 and IPv6, an optional DTLS session and a SOCKS5 path, and the transport the whole STUN, TURN, ICE and WebRTC stack is built on.
Send and receive UDP datagrams from Delphi/C++Builder. IPv4 and IPv6, an optional DTLS session and a SOCKS5 path, and the transport the whole STUN, TURN, ICE and WebRTC stack is built on.
High-performance UDP datagram client — the foundation under STUN, TURN, ICE, RTCPeerConnection and any custom UDP protocol you write.
TsgcUDPClient
Windows, macOS, Linux, iOS, Android
Core / Standard / Professional / Enterprise
Set Host / Port, Active := True, then call WriteData with the text or the bytes you want to send. Inbound datagrams arrive on OnUDPRead.
uses
sgcP2P, sgcUDP_Classes, sgcSocket_Classes;
// TFormUDP holds FClient: TsgcUDPClient and FIncoming: TStringList
procedure TFormUDP.CreateClient;
begin
FClient := TsgcUDPClient.Create(nil);
FClient.Host := '127.0.0.1';
FClient.Port := 4000;
FClient.OnUDPRead := OnUDPRead;
FClient.Active := True;
FClient.WriteData('hello over UDP');
end;
procedure TFormUDP.OnUDPRead(Sender: TObject; Socket: TsgcUDPSocket;
Bytes: TsgcBytes);
var
oStream: TStringStream;
begin
// fires on the read thread, marshal before you touch a control
oStream := TStringStream.Create('');
try
oStream.Write(Bytes[0], Length(Bytes));
FIncoming.Add(oStream.DataString);
finally
oStream.Free;
end;
end;
// includes: sgcP2P.hpp, sgcUDP_Classes.hpp, sgcSocket_Classes.hpp
TsgcUDPClient *Client = new TsgcUDPClient(this);
Client->Host = "127.0.0.1";
Client->Port = 4000;
Client->OnUDPRead = OnUDPRead;
Client->Active = true;
Client->WriteData("hello over UDP");
void __fastcall TFormUDP::OnUDPRead(TObject *Sender,
TsgcUDPSocket *Socket, TsgcBytes Bytes)
{
// fires on the read thread, marshal before you touch a control
}
A thin, predictable UDP socket layer used as the transport for STUN / TURN / ICE / WebRTC and any custom datagram protocol.
WriteData(text) and WriteData(bytes) queue a datagram to Host / Port, and the overloads that take an address send one anywhere else. OnUDPRead delivers every inbound packet together with the socket it arrived on.
Set DTLS := True and fill DTLSOptions to carry the datagrams inside a DTLS session. OnDTLSVerifyPeer hands you the peer certificate so you decide whether to accept it.
Proxy carries the datagrams through a SOCKS5 UDP ASSOCIATE. An HTTP proxy is refused with EsgcUDPProxyNotSupported, because only SOCKS5 defines a UDP path.
Every OnUDPRead carries a TsgcUDPSocket: IP and Port name the sender, LocalIP and LocalPort name the local base that ICE later publishes as a host candidate.
IPVersion is handed straight to the underlying socket, so set it to Id_IPv6 when you need the IPv6 path.
Every higher P2P component (TsgcSTUNClient, TsgcTURNClient, TsgcICEClient, TsgcRTCPeerConnection) uses this client internally as its UDP transport.
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. | 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 |