TsgcQUICClient › Methods › OpenStream

OpenStream Method

Opens a new client-initiated QUIC stream on the active connection and returns its wrapper.

Syntax

function OpenStream(aUnidirectional: Boolean = False): TsgcQUICClientStream;

Parameters

NameTypeDescription
aUnidirectionalBooleanWhen True opens a unidirectional stream, which the client can only write to. When False (the default) opens a bidirectional stream, which can carry data in both directions.

Return Value

The wrapper for the newly opened stream, or nil when the stream could not be opened. (TsgcQUICClientStream)

Remarks

OpenStream creates a new client-initiated stream on the live connection and returns a TsgcQUICClientStream wrapper exposing StreamId, Unidirectional and Incoming. Pass the wrapper to WriteStreamData to send over it. Data that arrives back on the stream is reported through OnQUICStreamData, matched by StreamId.

Always check the result for nil. The method returns nil rather than raising when there is no live connection, when SSLQUIC is False, or when OpenSSL refuses to create the stream, for instance because the peer's stream limit has been reached.

Call EnableMultiStream first, on the established connection. Without it the connection is not in multi-stream mode and nothing read back on the stream is reported.

The returned wrapper is owned by the connection and is freed with it, do not free it yourself. Each QUIC stream is independently ordered, so a lost packet on one stream does not stall the others, which is the head-of-line blocking that HTTP/2 over TCP suffers from.

This member is currently available in the Delphi/C++Builder implementation only, and it requires the builtin OpenSSL QUIC engine.

Example


var
  oStream: TsgcQUICClientStream;
begin
  oClient.EnableMultiStream;

  oStream := oClient.OpenStream; // bidirectional
  if Assigned(oStream) then
  begin
    Log('opened stream ' + IntToStr(oStream.StreamId));
    oClient.WriteStreamData(oStream, TEncoding.UTF8.GetBytes('Hello QUIC'));
  end
  else
    Log('could not open the stream');
end;

Back to Methods