I’m trying to make my DOTS game playalbe via Unity Relay. The issue is my client doesn’t connect to the server even though I pass port and ip to it.
Thats my connection manger code
public void StartRelayHost(int port, string conIP)
{
DestoryLocalSimulationWorld();
SceneManager.LoadScene(1);
var serverWorld = ClientServerBootstrap.CreateServerWorld("server");
ushort Port = (ushort )port;
var listenReq = ServerWorld.EntityManager.CreateEntity(typeof(NetworkStreamRequestListen));
ServerWorld.EntityManager.SetComponentData(listenReq,new NetworkStreamRequestListen {Endpoint = ClientServerBootstrap.DefaultListenAddress.WithPort(Port)});
StartRelayClient(port, conIP);
}
private void StartRelayClient(int port, string conIP)
{
Debug.Log("server" + port + " " + conIP);
DestoryLocalSimulationWorld();
SceneManager.LoadScene(1);
Debug.Log("client " + port + " " + conIP);
var clientWorld = ClientServerBootstrap.CreateClientWorld("client");
ushort Port = (ushort )port;
var connectionEndpoint = NetworkEndpoint.Parse(conIP, Port);
{
using var query =
clientWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
query.GetSingletonRW<NetworkStreamDriver>().ValueRW.Connect(clientWorld.EntityManager,connectionEndpoint);
}
World.DefaultGameObjectInjectionWorld = clientWorld;
}
And thats how i pass Relay data
public async void CreateRelay()
{
try
{
Allocation allocation = await RelayService.Instance.CreateAllocationAsync(3);
joincode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
_connectionManager.StartRelayHost(allocation.RelayServer.Port ,allocation.RelayServer.IpV4);
}
catch(RelayServiceException e)
{
Debug.Log(e);
}
}
With this set-up my client is always on connecting even though server and subscene seem to load correctly
New contributor
Marek Kurowski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.