question

Abdulhai Moubarak avatar image
Abdulhai Moubarak asked

Unity Mirror Playfab Multiplayer Connecting to the Server

if the server is active and have a session ID in Playfab - the game (mirror) doesn't connect to it

if the server is in Standby and have no session ID - the game connects successfully every time to the ip and port

what can I do ?

Custom Game Serversmultiplayer
4 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.

Seth Du avatar image Seth Du ♦ commented ·

May I ask how do you get the IP and port when a server is in standby and no session ID? Usually there are only 2 methods to get IP and port -- via RequestMultiplayerServer API or GetMatch API.

0 Likes 0 ·
Abdulhai Moubarak avatar image Abdulhai Moubarak Seth Du ♦ commented ·

I am using RequestMultiplayerServer

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Abdulhai Moubarak commented ·

Do you mean after RequestMultiplayerServer is called, you can not connect the server instance using the IP and port from callback result?

Still, to help you solve this issue, may I know how do you get the IP and port when a server is in standby and no session ID? Is it from a previous call?

0 Likes 0 ·
Show more comments
Abdulhai Moubarak avatar image
Abdulhai Moubarak answered

Found the Issue

In the Mirror version I am using v32.1.4 (maybe all future versions not sure)

you should not set the network manager to listen in AgentListener.cs in the official MpsSamples

here :

https://github.com/PlayFab/MpsSamples/blob/master/UnityMirror/UnityServer/Assets/Server/Scripts/AgentListener.cs

after this small change everything works great now

private void OnServerActive()
    {
        UnityNetworkServer.Instance.StartListen();  //<----------------Remove This line
        Debug.Log("Server Started From Agent Activation");
    }

I guess that's why for me it was working when connecting to a standby server

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.

steve18624@gmail.com avatar image steve18624@gmail.com commented ·

This solved my problem as well. Thanks Abdulhai! I spent many hours on this bug.

0 Likes 0 ·
steve18624@gmail.com avatar image steve18624@gmail.com steve18624@gmail.com commented ·

I forgot to mention that I haven't figured out why this works yet. This should cause an error in the Mirror NetworkManager. TelepathyTransport should be listening on the wrong port. Without overriding it, it is listening on whatever port was set in the inspector before build.

The Mirror Server port is set by Agent listener as follow:

NetworkManagerCustom.Instance.Port = portInfo.Single().ServerListeningPort.


When we comment out StartListen.

    [Server]
    private void OnServerActive()
    {
        //NetworkManagerCustom.Instance.StartListen();
        Debug.Log("Server Started From Agent Activation");
    }

The Server never sets the Mirror Telepathy Port to the one provided by AgentListener/PlayFab because the following code is the only place that the port is set by NetworkManager:

#if ENABLE_PLAYFABSERVER_API
    public void StartListen()
    {
        this.GetComponent<TelepathyTransport>().port = (ushort)Port;
        NetworkServer.Listen(maxConnections);
0 Likes 0 ·
Seth Du avatar image
Seth Du answered

To be clear, an instance won’t switch back to standby state. The Lifecycle of a server instance ends when it is shutdown, while the resource will be released to the pool. The standby server you have seen is a newly created one by Docker.

You should not cache any IP and port because that information will be invalid when this instance is shutdown. You can still connect to the server build possibly because the server still in shutdown process or other states like onMaintenance and you don’t define any codes to destroy connections when entering shutdown process.

Each server instance is independent (so are the IP and port) and you cannot use an old IP and port to connect a new instance.

1 comment
10 |1200

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

Abdulhai Moubarak avatar image Abdulhai Moubarak commented ·

connectingplayfab.png

@SethDu please check the Image

0 Likes 0 ·
connectingplayfab.png (173.8 KiB)

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]