TsgcUDPCLient › Events › OnUDPRead
Viene generato quando un datagramma UDP in entrata è stato ricevuto dal peer.
property OnUDPRead: TsgcUDPReadEvent;
// TsgcUDPReadEvent = procedure(Sender: TObject; Socket: TsgcUDPSocket; Bytes: TsgcBytes) of object
—
Generato una volta per datagramma ricevuto, passando i byte grezzi attraverso il parametro Bytes e il Socket di origine (che espone PeerIP e PeerPort del mittente). Il payload viene sempre consegnato come byte; convertirlo con TEncoding se il protocollo applicativo utilizza testo. Il thread che attiva questo evento dipende dalla proprietà NotifyEvents: neAsynchronous instrada tramite una coda in background, neSynchronous usa Synchronize e neNoSync si attiva direttamente sul thread lettore. Quando DTLS è abilitato, Bytes contiene il testo in chiaro decrittografato.
procedure TForm1.oClientUDPRead(Sender: TObject; Socket: TsgcUDPSocket;
Bytes: TsgcBytes);
begin
Memo1.Lines.Add(Format('From %s:%d -> %s',
[Socket.PeerIP, Socket.PeerPort, TEncoding.UTF8.GetString(Bytes)]));
end;