Proper way to destroy NetworkMatches

What’s the proper way to destroy a NetworkMatch?

When I try to use DestroyMatch on the NetworkMatch with either creating a DestroyMatchRequest with the networkId set or just passing the networkId from the MatchInfo I get the following Response:

I’m basically making a game that automatically matches up two people at “random”.
I first search the MatchList and if there is no suitable match it creates one and acts as the host or if one is found it joins as a client. So either after connecting the clients or after the game ends I want the Match to be removed. But I don’t seem to be able to manually remove it. Meaning sometimes if I try to start a new game just after ending another one it will find the remainder of the old match and try to join it, basically connecting to nobody.
Destroying the NetworkMatch component doesn’t change anything either.

Matches are cleaned up automatically, as are clients that don’t send a packet to relay for 30 seconds. That’s the shortly after timing window you’re seeing.

That error looks like a poorly formatted way of the server saying the client you’re connecting from is already disconnected; Once that happens it can no longer manage the network it was involved in.

In other words, in order to destroy a network the client requesting the destruction needs to be the host for the match and connected. It looks like the disconnection had already happened in this case.

What exactly is the host connection though? Because when you create a match you don’t have to actually join it.
I get the exact same error when I try to destroy the match just after both the client/server and the client connected to each other, so when they apparently are still connected because that connection has just been established through the MatchInfo.

This is a simplified version of my connection logic. Am I missing something? All of it gets called, just with a failure for the DestroyMatch. Setting the access token does not change the behaviour. (Am I missing something?)

    public void OnServerConnect(NetworkMessage msg) {
        networkMatch.DestroyMatch(matchInfo.networkId, OnMatchDestroy);
    }

    public void OnMatchCreate(CreateMatchResponse createMatchResponse) {
        if (createMatchResponse.success) {
            //Utility.SetAccessTokenForNetwork(createMatchResponse.networkId, new NetworkAccessToken(createMatchResponse.accessTokenString));
            matchInfo = new MatchInfo(createMatchResponse);
            NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect);
        
            ConnectionConfig config = new ConnectionConfig();
            config.AddChannel(QosType.ReliableSequenced);
            config.AddChannel(QosType.ReliableSequenced);
            NetworkServer.Configure(config, 2);
       
            if (NetworkServer.Listen(matchInfo, 6789)) {
                client = ClientScene.ConnectLocalServer();

                ClientScene.RegisterPrefab(playerPrefab);
                ClientScene.RegisterPrefab(ballPrefab);
            } else {
                Debug.LogError("Error listening on port " + 6789);
            }
        } else {
            Debug.LogError("Error creating match");
        }
    }

    public void OnMatchJoined(JoinMatchResponse joinMatchResponse) {
        if (joinMatchResponse.success) {
            //Utility.SetAccessTokenForNetwork(joinMatchResponse.networkId, new NetworkAccessToken(joinMatchResponse.accessTokenString));
            matchInfo = new MatchInfo(joinMatchResponse);
            client = new NetworkClient();

            ConnectionConfig config = new ConnectionConfig();
            config.AddChannel(QosType.ReliableSequenced);
            config.AddChannel(QosType.ReliableSequenced);
            client.Configure(config, 1);

           ClientScene.RegisterPrefab(ballPrefab);
           ClientScene.RegisterPrefab(playerPrefab);

           client.Connect(matchInfo);
        } else {
            Debug.LogError("Error joining match");
        }
}

I would like some more information on this as well as I am running into the same issue. Is it making the assumption that server would also be connected to the server as a client ?

Is there anything on this ? I am still having this issue and its actually preventing me from using this service because I don’t want stale rooms showing up on the list.

I’ve been busy the last few weeks but I see nothing much has changed. Can we get an update on this Jeremy?

For me it’s even worse since I have automatic matchmaking and it basically connects the clients to empty matches.

Even if we pretend this would work, I’m seeing a problem:
If the host disconnects unintentionally (because his connection drops), you would still end up with the same issue.

So I think it would make more sense if the MatchList request wouldn’t return empty matches to begin with. - Which I suggested in another thread, but no info on that yet.

In theory there might be use cases for empty Matches, like creating one but for whatever reason not joining directly.
You could also just filter matches with 0 people in them but it would still be nice if this was actually working.

FYI there is a channel on irc.freenode.net (#unity3d-unet) where people might have more answers eventually, seeing as unet is still in it’s infancy :wink:

And some other resources here: UNET Refs and Tutorials - Google Docs

I’m not so sure about that. You couldn’t join that empty match afterwards, since you can’t join matches with no host in it.

How would you do that? I’m genuinely curious. ListMatch requests have no filter for that, and even the matches themselves don’t seem to expose the number of players inside them.

You get back a list of matches though and the info tells you how many people are connected to it.

The problem is that in my case it still says there is one connection on it even though there isn’t.

I have been trying to do the same thing. The only quick solution I presume would be to have an offline list of matches, that you failed to join and the filter them out by yourself.

This is the code I use for my simple 1v1 matchmaker:

void OnMyMatchList(ListMatchResponse matchList){
        for (int i = 0; i < matchList.matches.Count; i++) {
// Also check if failed to connect
            if(matchList.matches[i].currentSize > 1)
                continue;
            matchMaker.JoinMatch(matchList.matches[i].networkId, "", OnMatchJoined);
            return;
        }
        //            startMyOwn
        matchMaker.CreateMatch("name", 2, true, "", OnMatchCreate);

    }

When I join an empty server (the second time at least), I get an error like this:

But when I join the empty server the first time, it fails silently

I hope there is a way to determine if everything went well on the callback “OnMatchJoined” (since it always fires), because the only other way is to check manually after a few seconds if you actually joined, but that would be also very slow and unreliable.

The reason empty servers are created is that I can turn off my android game without quitting properly, f.e. Build&Run. If I quit, I can destroy match and it gets removed almost always.

I don’t get it… but Unity 5 is still in beta!!!:face_with_spiral_eyes:
It’s a few days that I using the new Networking and I found more problems than solutions here!

Hi, anybody found a solution to this? Still happening to me :frowning: Basically matchmaking is useless for final product thanks to this :frowning:

Having this issue too. Any known solutions?

Ping

I have the same problem… if the host disconnects, and tries to connect a few seconds after, he joins an empty lobby.
Checking the number of players in the room does not help as it states there is one player, even if there is 0…

Same here, hope they fix it soon :confused:

same here

This is definitely not happening.

  • I have a match that won’t go away. I’ve tried rebooting, quitting Unity, etc. It’s not going away.
  • I can attempt to Join it (it seems to think 4 players are connected) even though I’m the only one trying it (it’s in development)
  • If I try to create a match I get an error that looks like my CCU is exceeded? However according to the list I only have 1 match that is 4 of 20 players?

Please advise…

Create Failed:[[UnityEngine.Networking.Match.CreateMatchResponse]-success:False-extendedInfo:Failed; CCU exceeded for appId=725151]-address:,port:0,networkId:0x0000000000000000,nodeId:0x0000,usingRelay:False
UnityEngine.Networking.NetworkManager:OnMatchCreate(CreateMatchResponse)
NetworkController:OnMatchCreate(CreateMatchResponse) (at Assets/_Assets/Scripts/Networking/NetworkController.cs:194)
UnityEngine.Networking.Match.c__Iterator0`1:MoveNext()

1 Like

I am also experiencing this. In the past matches that were hosted and improperly exited (i.e. stop the debugger without leaving match cleanly) would be cleaned up in approximately 30 seconds. Today I’ve run into a scenario where a game that I created is lingering and isn’t being GC’d due to inactivity. Also attempted quitting Unity / disconnecting network for minutes / rebooting same as @carmine .