question

longtoothgames avatar image
longtoothgames asked

Disconnect from server when calling PlayFabMultiplayerAPI.RequestMultiplayerServer, but not when using the IP and Port directly.

I'm developing my networking game flow based off these two projects using Unity and Mirror. Title C8E30 (currently testing on the server: Word Client/Server Test UDP 4

https://github.com/natepac/playfabmirrorgameexample/tree/master

https://github.com/PlayFab/MpsSamples/tree/master/UnityMirror

I'm using a game configuration object in this version. If there is no IP in the configuration, I call PlayFabMultiplayerAPI.RequestMultiplayerServer and add the IP and Port to the network manager, then connect. I get the correct information, but seem to be immediately disconnected (client times out). When I use the same information directly in the configuration and skip the call to RequestMultiplayerServer, I connect and have no issues.

Same issues with matchmaking. I get the match and try for the server and get disconnected.

The calls to obtain the server info seem to be doing something server-side, but I'm not sure what. I put a 1 minute server shutdown timer on which seems to work fine (when connecting directly). I removed the empty server check when a player is removed (for testing purposes). Here are the code sections where I'm calling from the client.

        //currently called from UI button
        public void ConnectToGameServer()
        {
            if (_mGameConfiguration.IpAddress == "")
                RequestMultiplayerServer();
            else
                ConnectRemoteClient();
        }




        private void RequestMultiplayerServer()
        {
            Debug.Log("[ClientStartUp].RequestMultiplayerServer");


            //We need to grab an IP and Port from a server based on the buildId.
            //Copy this and add it to your Configuration.
            RequestMultiplayerServerRequest requestData = new RequestMultiplayerServerRequest
            {
                BuildId = _mGameConfiguration.BuildId,
                SessionId = System.Guid.NewGuid().ToString(),
                PreferredRegions = new List<string>() { Enum.GetName(typeof(AzureRegion), AzureRegion.EastUs) }
            };


            PlayFabMultiplayerAPI.RequestMultiplayerServer(requestData, OnRequestMultiplayerSuccess, OnPlayFabCallbackError);
        }






        private void OnRequestMultiplayerSuccess(RequestMultiplayerServerResponse response)
        {
            //TODO debugging code
            string message = "";


            foreach (ConnectedPlayer player in response.ConnectedPlayers)
            {
                message += $"Player: {player.PlayerId}\n";
            }
            message += $"IP: {response.IPV4Address}\n";
            message += $"Port: {response.Ports[0].Name} Protocol: {response.Ports[0].Protocol}\n";
            message += $"ServerID: {response.ServerId}\n";
            message += $"GameState: {response.State}\n";
            OnUiMessage?.Invoke("Have Server", message);
            Debug.Log($"[ClientStartUp].OnRequestMultiplayerSuccess:\n {message}");




            ConnectRemoteClient(response);
        }






        private void ConnectRemoteClient(RequestMultiplayerServerResponse response = null)
        {
            if (response == null)
            {
                _mUNetManager.networkAddress = _mGameConfiguration.IpAddress;
                _mTransport.Port = _mGameConfiguration.Port;
            }
            else
            {
                _mUNetManager.networkAddress = response.IPV4Address;
                _mTransport.Port = (ushort)response.Ports[0].Num;
                //TODO BUG find out why we disconnect in a short time on this one, possibly stop shutdown timer on server when player connected
            }
            _mUNetManager.StartClient();
        }
,

I'm developing my networking game flow based off these two projects using Unity and Mirror. Title C8E30 (currently testing on the server: Word Client/Server Test UDP 4

https://github.com/natepac/playfabmirrorgameexample/tree/master

https://github.com/PlayFab/MpsSamples/tree/master/UnityMirror

I'm using a game configuration object in this version. If there is no IP in the configuration, I call PlayFabMultiplayerAPI.RequestMultiplayerServer and add the IP and Port to the network manager, then connect. I get the correct information, but seem to be immediately disconnected (client times out). When I use the same information directly in the configuration and skip the call to RequestMultiplayerServer, I connect and have no issues.

Same issues with matchmaking. I get the match and try for the server and get disconnected.

The calls to obtain the server info seem to be doing something server-side, but I'm not sure what. I put a 1 minute server shutdown timer on which seems to work fine (when connecting directly). I removed the empty server check when a player is removed (for testing purposes). Here are the code sections where I'm calling from the client.

        //currently called from UI button
        public void ConnectToGameServer()
        {
            if (_mGameConfiguration.IpAddress == "")
                RequestMultiplayerServer();
            else
                ConnectRemoteClient();
        }




        private void RequestMultiplayerServer()
        {
            Debug.Log("[ClientStartUp].RequestMultiplayerServer");


            //We need to grab an IP and Port from a server based on the buildId.
            //Copy this and add it to your Configuration.
            RequestMultiplayerServerRequest requestData = new RequestMultiplayerServerRequest
            {
                BuildId = _mGameConfiguration.BuildId,
                SessionId = System.Guid.NewGuid().ToString(),
                PreferredRegions = new List<string>() { Enum.GetName(typeof(AzureRegion), AzureRegion.EastUs) }
            };


            PlayFabMultiplayerAPI.RequestMultiplayerServer(requestData, OnRequestMultiplayerSuccess, OnPlayFabCallbackError);
        }






        private void OnRequestMultiplayerSuccess(RequestMultiplayerServerResponse response)
        {
            //TODO debugging code
            string message = "";


            foreach (ConnectedPlayer player in response.ConnectedPlayers)
            {
                message += $"Player: {player.PlayerId}\n";
            }
            message += $"IP: {response.IPV4Address}\n";
            message += $"Port: {response.Ports[0].Name} Protocol: {response.Ports[0].Protocol}\n";
            message += $"ServerID: {response.ServerId}\n";
            message += $"GameState: {response.State}\n";
            OnUiMessage?.Invoke("Have Server", message);
            Debug.Log($"[ClientStartUp].OnRequestMultiplayerSuccess:\n {message}");




            ConnectRemoteClient(response);
        }






        private void ConnectRemoteClient(RequestMultiplayerServerResponse response = null)
        {
            if (response == null)
            {
                _mUNetManager.networkAddress = _mGameConfiguration.IpAddress;
                _mTransport.Port = _mGameConfiguration.Port;
            }
            else
            {
                _mUNetManager.networkAddress = response.IPV4Address;
                _mTransport.Port = (ushort)response.Ports[0].Num;
                //TODO BUG find out why we disconnect in a short time on this one, possibly stop shutdown timer on server when player connected
            }
            _mUNetManager.StartClient();
        }
sdksmultiplayer
2 comments
10 |1200

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

longtoothgames avatar image longtoothgames commented ·

Sorry for the double post, couldn't find a way to edit it out.

0 Likes 0 ·
longtoothgames avatar image longtoothgames commented ·

Since I can't seem to edit, I have some updated information from testing with the local agent, I posted over on Unity.

https://forum.unity.com/threads/issues-with-playfab-multiplayer-example-when-updating-mirror.1243054/

0 Likes 0 ·

1 Answer

·
longtoothgames avatar image
longtoothgames answered

Seem to have fixed it. Turned off autobuild and changed some of the NeworkServer calls to let NetworkManager handle them instead

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.