NetCode for ECS: dynamic port listening / relay

For the first point you can do this inside of a system, will this be what you are looking for?:

var connectionEntity SystemAPI.GetSingletonEntity<NetworkStreamConnection>()
var connection = EntityManager.GetComponentData<NetworkStreamConnection>(connectionEntity);
var port = SystemAPI.GetSingletonRW<NetworkStreamDriver>().ValueRO.GetRemoteEndPoint(connection).Port;```

The second point regarding passing the **RelayServerData** to the **NetworkSettings**, you can see an example of this in the **DefaultDriverConstructor.RegisterClientDriver** here we have an override that allows passing the RelayServerData to the driver together with some default **NetworkSettings**.

To do this you can make a simple implementation of **INetworkStreamDriverConstructor**:

```csharp
public struct SecureDriverConstructor : INetworkStreamDriverConstructor
{
    public void CreateClientDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug)
    {
        var yourRelayServerData = // code for getting your data for the client;
        DefaultDriverBuilder.RegisterClientDriver(
                world, ref driverStore, netDebug, yourRelayServerData;
    }

    public void CreateServerDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug)
    {
        var yourRelayServerData = // code for getting your data for the server;
        DefaultDriverBuilder.RegisterServerDriver(
                world, ref driverStore, netDebug, yourRelayServerData;
    }
}

A similar question was answered here: Relay with Netcode for entities - how to connect local client