Hey miniwolf_unity,
thanks for the reply!
Unfortunately, for the first point, it would only work on the client, once he is connected, that is why I wanted a way to receive on the server his listening port, which I think can be technically accessed from the GetLocalEndpoint.
For the second point, I will definitely check it out, my only concern about that way was, I have to tell right from the beginning if I want to have a relay in or not, as basically the network setting is baked into the drivers, I would like a more modular approach, where I can change the network settings as I want on the fly.
Btw, I found a bug (exception) inside the NetworkStreamListenSystem, it is never initializing
private ComponentLookup<ConnectionState> m_ConnectionStateFromEntity;
And therefore the OnUpdate of it will throw a null ref exception here:
public void OnUpdate(ref SystemState systemState)
{
var netDebug = SystemAPI.GetSingleton<NetDebug>();
ref var networkStreamDriver = ref SystemAPI.GetSingletonRW<NetworkStreamDriver>().ValueRW;
var ents = m_ConnectionRequestListenQuery.ToEntityArray(Allocator.Temp);
m_NetworkStreamRequestListenFromEntity.Update(ref systemState); <--- HERE IT WILL THROW
var requestFromEntity = m_NetworkStreamRequestListenFromEntity;
...
}
Cheers
Edit:
I dug a bit deeper into your suggestion for the relay issue, but I see a problem here.
Of course, I can initialize the Drivers with my relay setting, but I can never change it, and that is a big problem, as basically every host/join attempt could require new relay data, which I can not pass anymore, as the drivers and their network settings have been initialized already and I cant access it.
Here is also my custom Bootstrap if anyone is interested:
using Unity.Entities;
using Unity.NetCode;
using Unity.Networking.Transport.Relay;
using UnityEngine.Scripting;
public enum ProtocolType
{
UnityTransport,
RelayUnityTransport,
}
[Preserve]
public class GameBootstrap : ClientServerBootstrap
{
struct RelayIPCAndSocketDriverConstructor : INetworkStreamDriverConstructor
{
public static RelayServerData relayData;
public void CreateClientDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug) => DefaultDriverBuilder.RegisterClientDriver(world, ref driverStore, netDebug, ref relayData);
public void CreateServerDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug) => DefaultDriverBuilder.RegisterServerDriver(world, ref driverStore, netDebug, ref relayData);
}
static GameBootstrap instance;
bool initialised;
ProtocolType protocol;
public static ProtocolType Protocol => instance.protocol;
public static void InitializeNetCode(RelayServerData? relayServerData) => instance.Initialize(relayServerData);
public override bool Initialize(string defaultWorldName)
{
instance = this;
return false;
}
void Initialize(RelayServerData? relayServerData)
{
if (initialised)
return;
if (relayServerData.HasValue)
{
RelayIPCAndSocketDriverConstructor.relayData = relayServerData.Value;
NetworkStreamReceiveSystem.DriverConstructor = new RelayIPCAndSocketDriverConstructor();
protocol = ProtocolType.RelayUnityTransport;
}
else
protocol = ProtocolType.UnityTransport;
initialised = true;
base.Initialize(null);
}
}
Edit 2:
Another issue found, your RegisterServerDriver method calls RegisterClientDriverā¦
public static void RegisterServerDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug, ref RelayServerData relayData, int playerCount = 0)
{
var settings = GetNetworkServerSettings(playerCount: playerCount);
settings = settings.WithRelayParameters(ref relayData);
RegisterClientDriver(world, ref driverStore, netDebug, settings);
}
Edit 3:
Would be great when we use the CreateServerDriver/CreateClientDriver with the relay setting, that it would skip the IPC transport layer, as it throws an exception if the relay is encountered 
Edit 4:
I finally also succeeded to have a local server&client using relay. So I start a server listening on relay, while also connecting to it (but I can only get it working by also using the relay service, to retrieve the relay data.
In general that has multiple negative impacts, 1. the players own connection is based on the relay service, 2. the player is having a ping (like 40 for me) to his own game xD)
Therefore:
How can I achieve a local connection to my server, which is hosting utilizing the relay server, without also going through the relay server? How can I āhostā a game, as a server, and have network components as a āclientā without establishing a real connection, that would solve kind of all my problems