Search Unity

Question Cannot Connect to Local Playfab Server

Discussion in 'NetCode for ECS' started by ogimusprime, Sep 22, 2023.

  1. ogimusprime

    ogimusprime

    Joined:
    Jul 20, 2021
    Posts:
    11
    Please if anyone can help me with this I would be very grateful. I am at a loss about what I am doing wrong which prevents me from connecting my client Unity build to my local Playfab server.
    For context, I am running a Linux dedicated server Unity build in a docker Linux container. I am trying to use Playfab for my server hosting, but before that I am utilizing their local multiplayer agent in order to debug my game locally. I believe the Playfab server is starting up correctly as it debugs that the server is in the active state.

    This is being debugged in the Docker container log after server startup:

    "Server networkStreamDriver is listening on: 0.0.0.0:7778
    publicIpV4Address: 127.0.0.1
    Environment: LOCAL"


    In my scripts on the server side, I create the server world:


    Code (CSharp):
    1. Debug.Log("SERVER WORLD CREATED");
    2. server = ClientServerBootstrap.CreateServerWorld("ServerWorld");
    3. World.DefaultGameObjectInjectionWorld ??= server;

    and then I tell the server to listen on the proper port:

    Code (CSharp):
    1. var drvQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
    2. drvQuery.GetSingletonRW<NetworkStreamDriver>().ValueRW.Listen(NetworkEndpoint.AnyIpv4.WithPort((ushort)ServerStartup.Instance.Port));
    3. Debug.Log($"Server networkStreamDriver is listening on: {NetworkEndpoint.AnyIpv4.WithPort((ushort)ServerStartup.Instance.Port)}");
    4. drvQuery.Dispose();
    On the client side I create the client world:

    Code (CSharp):
    1.  
    2. Debug.Log("cLIENT WORLD CREATED");
    3. client = ClientServerBootstrap.CreateClientWorld("ClientWorld");
    4. World.DefaultGameObjectInjectionWorld ??= client;
    Then I tell the client to connect to the server, this is done after the Docker logs have told me the server is active and listening on the proper port:

    Code (CSharp):
    1. var endpoint = NetworkEndpoint.LoopbackIpv4.WithPort(7778);
    2. var drvQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
    3. connectionEnt = drvQuery.GetSingletonRW<NetworkStreamDriver>().ValueRW.Connect(World.DefaultGameObjectInjectionWorld.EntityManager, endpoint);
    4. m_Stream = drvQuery.GetSingletonRW<NetworkStreamDriver>().ValueRW;
    5. drvQuery.Dispose();
    This is the debug I have in the client update loop:

    Code (CSharp):
    1. Debug.Log($"Client update loop: is client connected? {m_Stream.GetConnectionState(World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<NetworkStreamConnection>(connectionEnt))}");
    This debug only ever says "Connecting". For some reason, I get no error in this connection process, it just never changed from the "Connecting" state. Am I missing a step here? I am not doing anything with NetworkDriverStores or NetworkDrivers, should I be? I am also not yet calling

    networkDriver.ScheduleUpdate().Complete();


    Because I am only trying to establish an initial connection. Could that be giving me trouble? Another thing is that both my Server and Client builds exist in the same Unity project, I just have separate scenes for the Server and the Client which are the only scenes included in their respective builds. Will this cause any issues?

    A debug I am getting is

    "Create client default socket network interface driver"


    I am not sure what this means exactly, any insights?

    I have been trying for 2 weeks to get this client to connect to my local server to no avail. What I have posted is the only code in my project relating to Netcode for Entities, so if I am missing a crucial step please let me know, thank you!!
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Hey! Apologies for the delay.

    1. Replace World.DefaultGameObjectInjectionWorld.EntityManager with client.EntityManager.
    2. Other than that, this looks correct.
    This implies that the UDP Unity Transport connect payloads are never arriving on the server. Can you check with wireshark? It could be that docker is failing to forward those packets, or that your cloud is firewall blocking those packets. Can you successfully ping your server machine?

    No, you shouldn't need to call any manual driver related flows to get this to work. NetworkStreamReceiveSystem (a netcode package system) handles all that for you. Calling connect should be sufficient (and you're already doing that).

    No, this is fine too.

    Can you connect to your client world to your server world in the editor? Via the PlayMode tools "Client & Server" dropdown option?

    This is just a log saying that netcode has created* (typo) the client default socket network interface driver. Perfectly normal. You can find it here: DefaultDriverConstructor.cs:259.