question

ogburnzach avatar image
ogburnzach asked

Unity Server/Client Connection Workflow

I am trying to figure out what the workflow is to connect a client to a server which is running locally as a Linux container. My Game Development program is Unity and I would like to use Netcode for Entities for the Transport protocol. I am having a little difficulty because all of the examples I have found which talk about using Playfab servers locally to test your build are using Mirror for their transport stuff.

Currently I have my bootstrap file:

 switch (ClientServerBootstrap.RequestedPlayType)
         {
             case PlayType.Server:
                  
                 server = ClientServerBootstrap.CreateServerWorld("ServerWorld");
                 drvQuery = server.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
                 drvQuery.GetSingletonRW<NetworkStreamDriver>().ValueRW.Listen(ClientServerBootstrap.DefaultListenAddress.WithPort(Port));
                 drvQuery.Dispose();
                 World.DefaultGameObjectInjectionWorld ??= server;
                 break;
                
             case PlayType.Client:
                    
                 client = ClientServerBootstrap.CreateClientWorld("ClientWorld");
                 drvQuery = client.EntityManager.CreateEntityQuery(ComponentType.ReadWrite<NetworkStreamDriver>());
                 drvQuery.GetSingletonRW<NetworkStreamDriver>().ValueRW.Connect(client.EntityManager, ClientServerBootstrap.DefaultConnectAddress.WithPort(Port));
                 World.DefaultGameObjectInjectionWorld ??= client;
                 break;
 }

Which I believe works as intended. I then Try to connect my client to the server. I know the server is running correctly because the Docker logs show that the local Playfab server is in the active state. The steps I take to try to connect the client are:

1) authenticate client using LoginWithCustomIDRequest()

2) call RequestMultiplayerServer() using hard-coded values for the BuildID and SessionID which I obtain from the Docker debug logs

3) RequestMultiplayerServer() returns an error stating that the multiplayer server cannot be found.

Is this the correct workflow? Or do I need to connect the client to the server first after the login API call by creating a new Unity Entity and adding the NetworkStreamRequestConnect component to it. I believe this is the Unity Netcode for Entities equivalent to NetworkClient.Connect(networkAddress) in Mirror.

Any help would be greatly appreciated, especially if you have links/ references to using Unity Netcode for Entities in combination with Playfab servers. Thank you!

apis
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Infer Wang avatar image
Infer Wang answered

We don’t recommend Calling RequestMultiplayerServer on the client side, because there may be malicious players abuse this API. And the error” the multiplayer server cannot be found” may be caused that the region you specified in the request body doesn’t exist in the related build, please check it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.