TsgcQUICServer › Methods › WriteStreamData
Writes application bytes to one specific QUIC stream.
procedure WriteStreamData(const aStream: TsgcQUICServerStream; const aData: TBytes); virtual;
| Name | Type | Description |
|---|---|---|
aStream | const TsgcQUICServerStream | The target stream, either one returned by OpenStream or one found with aConnection.FindStreamById. The call does nothing when it is nil or has no OpenSSL handle. |
aData | const TBytes | The bytes to send. An empty array is a no-op. |
Sends aData on the individual stream identified by aStream. Unlike WriteData, which always targets the connection's default data stream, this method addresses one specific stream, which is what multi-stream transports such as WebTransport need.
The write is non-blocking. If the stream cannot accept the bytes yet, the server drives the QUIC event loop and retries, up to 100 attempts with a 1 ms pause between them, then flushes the queued bytes to the network. If the stream is still not writable after those attempts the method gives up silently, so the data is not sent and no exception is raised. This bound exists so a stalled peer cannot hang the pump thread forever.
Writing to a peer-opened unidirectional stream is not valid QUIC, the peer owns the write side. Only write to a stream whose Unidirectional is False, or to a unidirectional stream that you opened with OpenStream.
This method is currently available in the Delphi/C++Builder implementation only. The .NET implementation exposes no WriteStreamData.
// push on a server-opened one-way stream
oStream := oServer.OpenStream(aConnection, True);
if Assigned(oStream) then
oServer.WriteStreamData(oStream, TEncoding.UTF8.GetBytes('event: ping'));
// or answer on the stream the peer used, from OnQUICStreamData
procedure TfrmServer.OnQUICStreamDataEvent(Sender: TObject;
const aConnection: TsgcQUICServerConnection; aStreamId: Int64;
aUnidirectional: Boolean; const aData: TBytes);
var
oStream: TsgcQUICServerStream;
begin
if aUnidirectional then
Exit; // the peer owns the write side of its uni stream
oStream := aConnection.FindStreamById(aStreamId);
if Assigned(oStream) then
oServer.WriteStreamData(oStream, aData);
end;