1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.