TsgcQUICServer › Properties › Connections

Connections Property

The list of QUIC connections currently accepted by the server.

Syntax

property Connections: TObjectList read GetConnections;
// TObjectList<TsgcQUICServerConnection> on NEXTGEN compilers

Default Value

Empty list

Remarks

Read-only. Returns the list of live TsgcQUICServerConnection objects, one per accepted QUIC connection. The list is created on first access, so it is never nil. Use it to broadcast to every peer or to inspect sessions; to only count them, prefer ConnectionCount, which does not force the list into existence.

The server owns the list and its items. It adds a connection when the listener accepts one and removes (and frees) it when the peer disconnects or when Stop is called. Never add, delete or free entries yourself. To close one connection, set its Connected property to False.

Threading. In Delphi the list is not thread-safe and is mutated by the server's background listener thread, which accepts, reads and removes connections. Enumerating it from another thread (a UI timer, for example) can race with that thread and read a freed entry. The safe place to walk it is inside a QUIC event handler, because those run on the listener thread itself, so no concurrent mutation is in flight. If you must reach it from elsewhere, keep your own list that you maintain from OnQUICConnect and OnQUICDisconnect, guarded by your own lock.

In .NET the property is safer by construction: it returns a snapshot array taken under the server's internal lock, so enumerating it never races the accept loop, though entries may of course close while you iterate.

Since Delphi entries are typed TObjectList on classic compilers, cast an item to TsgcQUICServerConnection before use.

Example


// broadcast to every connected peer, called from a QUIC event handler
procedure TfrmServer.Broadcast(const aText: string);
var
  i: Integer;
  oConnection: TsgcQUICServerConnection;
  vBytes: TBytes;
begin
  vBytes := TEncoding.UTF8.GetBytes(aText);
  for i := 0 to oServer.Connections.Count - 1 do
  begin
    oConnection := TsgcQUICServerConnection(oServer.Connections[i]);
    if oConnection.Connected then
      oServer.WriteData(oConnection, vBytes);
  end;
end;

Back to Properties