TsgcQUICServer › Methods › OpenStream
Opens a new server-initiated QUIC stream on an existing connection.
function OpenStream(const aConnection: TsgcQUICServerConnection; aUnidirectional: Boolean): TsgcQUICServerStream; virtual;
| Name | Type | Description |
|---|---|---|
aConnection | const TsgcQUICServerConnection | The connection to open the stream on, typically the connection passed to an event handler. It must be connected, the call returns nil otherwise. |
aUnidirectional | Boolean | True opens a one-way (server to client) stream, False opens a bidirectional stream that the peer can also write on. |
The wrapper for the new stream, which is also added to the connection's Streams list, or nil on failure (TsgcQUICServerStream).
QUIC lets either endpoint open streams. OpenStream creates an additional stream on aConnection, separate from the default data stream that the peer opened and that WriteData targets. Pass the returned wrapper to WriteStreamData to send bytes on it.
The method returns nil rather than raising an exception when it cannot open the stream: when aConnection is nil or not connected, or when the loaded OpenSSL build does not export the QUIC stream API. Always test the result before using it.
The returned stream is owned by the connection and freed with it, so never free it yourself. Its StreamId is read back from OpenSSL and is -1 when the id could not be determined. A server-opened unidirectional stream is write-only, the transport never reads it, so it raises no OnQUICStreamData. A server-opened bidirectional stream is read, so the peer's replies on it do arrive through that event.
Reading additional streams requires multi-stream mode, see AlwaysMultiStream. Opening and writing one does not, OpenStream works on a plain single-stream connection too, you simply will not receive anything back on it. Server-initiated streams are what higher level transports such as WebTransport build on.
This method is currently available in the Delphi/C++Builder implementation only. The .NET implementation exposes no OpenStream.
var
oStream: TsgcQUICServerStream;
begin
oStream := oServer.OpenStream(aConnection, False);
if Assigned(oStream) then
begin
Log('opened stream id ' + IntToStr(oStream.StreamId));
oServer.WriteStreamData(oStream, TEncoding.UTF8.GetBytes('hello'));
end
else
Log('could not open the stream');
end;