TsgcWebTransportStream › Methods › Create
Constructs a stream bound to a session. The session calls this for you; applications do not.
constructor Create(const aSession: TsgcWebTransportSession;
aStreamId: Int64; aUnidirectional: Boolean); virtual;
| Name | Type | Description |
|---|---|---|
aSession | const TsgcWebTransportSession | The owning session. Becomes the read-only Session property and never changes. |
aStreamId | Int64 | The QUIC stream id, or -1 when it is not known yet. OpenStream passes -1 and lets the transport fill it in from OnOpenStream; AddIncomingStream passes the peer's real stream id. |
aUnidirectional | Boolean | True for a one-way stream, False for a bidirectional one. Becomes the read-only Unidirectional property and cannot be changed afterwards. |
You do not call this. A stream constructed by hand has no QUIC stream underneath it, no writer, and is not in any session's list, so writing to it does nothing and no data will ever be routed to it. Streams reach you already built and wired:
StreamId = -1, lets the transport bind a real QUIC stream through OnOpenStream, writes the WebTransport header and registers it. It returns the stream to you.OnStream event.
The constructor only records the three arguments and clears the HeaderSent and closed flags. It assigns no writer, sends nothing, and does not add the stream to the session; OpenStream and AddIncomingStream do all of that afterwards. It is public and virtual so a custom transport can construct streams, and so a descendant can extend one.
Ownership. Constructing a stream does not register it anywhere, so a stream you create yourself is yours to free. Every stream the library creates goes straight into the session's list, which owns and frees it. Never free a stream you received from OpenStream or OnStream, and never keep a reference to one past the lifetime of its session.
Note that aSession is only stored as a back-reference. Passing a session here does not register the stream with it, and does not make StreamCount go up.
This member is currently available in the Delphi/C++Builder implementation only. The .NET class has an equivalent constructor, but it is internal and cannot be called from application code.
// Applications never construct a stream. They receive one:
// Opened by us: OpenStream constructs, wires and registers it
FStream := FSession.OpenStream(False); // False = bidirectional
FStream.OnData := OnStreamData;
FStream.WriteData('Hello WebTransport');
// FStream is owned by FSession. Do not free it.
// Opened by the peer: it arrives already constructed and registered
procedure TfrmServer.OnWTStream(Sender: TObject;
const aStream: TsgcWebTransportStream);
begin
aStream.OnData := OnWTStreamData;
// aStream.Session, StreamId and Unidirectional are already set,
// and HeaderSent is True because the peer sent the header.
end;