- Home /
NetworkMatch Request Error Out of memory
I'm trying to use NetworkMatch
with NetworkTransport
as described unity's documentation here.
When listing matches, I have an Out of memory error and I can't find anything anywhere about this :
Exception: Match list failed : Request error:[Out of memory] Raw response:[] AVR.network.MyNetworkManager.OnMatchList (Boolean success, System.String extendedInfo, System.Collections.Generic.List²1 matches) (at Assets/Scripts/Network/MyNetworkManager.cs:207) UnityEngine.Networking.Match.NetworkMatch.OnMatchList (UnityEngine.Networking.Match.ListMatchResponse response, UnityEngine.Networking.Match.DataResponseDelegate²1 userCallback) (at C:/buildslave/unity/build/Runtime/Networking/Managed/MatchMakingClient.cs:357) UnityEngine.Networking.Match.NetworkMatch+c__Iterator0²2[UnityEngine.Networking.Match.ListMatchResponse,UnityEngine.Networking.Match.NetworkMatch+DataResponseDelegate²1[System.Collections.Generic.List²1[UnityEngine.Networking.Match.MatchInfoSnapshot]]].MoveNext () (at C:/buildslave/unity/build/Runtime/Networking/Managed/MatchMakingClient.cs:438) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
I'm using a simple NetworkManager script that deals with only one match : if the match is not created, it creates it, else it joins the match.
The problem is in updatePlayerCount()
wich just ask for the number of currently connected players, and in JoinOthers()
wich joins an already created match:
matchMaker.ListMatches(0, 1, MATCH, false, 0, 0, OnMatchListCountPlayers);
[...]
public void OnMatchListCountPlayers(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
{
if (!success)
throw new System.Exception("Match list failed : " + extendedInfo);
Here is the complete NetworkManager script I use:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.Types;
using UnityEngine.SceneManagement;
namespace AVR.network
{
[System.Serializable]
public class MyNetworkManager : MonoBehaviour
{
private const int BUFFER_SIZE = 1024;
private const string MATCH = "ITER";
private MatchInfo currentMatch = null;
private bool connectionDroped = false;
private int nPlayersOnline = -1;
public int NPlayersOnline { get { return nPlayersOnline; } }
private bool isStarted = false;
public bool IsStarted { get { return isStarted; } }
private bool isServer;
public bool IsServer { get { return isServer; } }
private bool isMatchCreator;
public bool IsMatchCreator { get { return isMatchCreator; } }
private NetworkMatch matchMaker;
private UnityAction callback;
[System.Serializable]
public class SpawnInfo
{
public string propertyName;
public string propertyValue;
public GameObject toSpawn;
}
public List<SpawnInfo> toSpawn;
private const int MAX_CONNECTION = 100;
private int port = 7543;
private int hostId;
private int webHostId;
private int reliableChannel;
private int unreliableChannel;
private byte error;
private string playerName;
private int connectionId;
private float connectionTime;
private int recHostId;
private int channelId;
private byte[] recBuffer = new byte[BUFFER_SIZE];
private int bufferSize = BUFFER_SIZE;
private int dataSize;
private NetworkEventType recData;
private Message msg;
void Awake()
{
matchMaker = gameObject.AddComponent<NetworkMatch>();
Application.runInBackground = true;
DontDestroyOnLoad(gameObject);
}
void Start()
{
if (Simulation.Instance != null)
Simulation.Instance.NetworkManager = this;
StartCoroutine(updatePlayerCount());
}
public void JoinOthers(string pName, UnityAction callback = null)
{
this.callback = callback;
this.playerName = pName;
if (matchMaker != null)
matchMaker.ListMatches(0, 1, MATCH, false, 0, 0, OnMatchList);
else
Debug.Log("Error with matchMaker !");
}
public void StartAlone(string pName, UnityAction callback = null)
{
this.callback = callback;
this.playerName = pName;
}
private void startServer()
{
NetworkTransport.Init();
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
HostTopology topo = new HostTopology(cc, MAX_CONNECTION);
hostId = NetworkTransport.AddHost(topo, port, null);
webHostId = NetworkTransport.AddWebsocketHost(topo, port, null);
isStarted = true;
isServer = true;
if (callback != null)
callback.Invoke();
Debug.Log("Server started on port " + port);
}
private void startClient(string serverIPAdress)
{
NetworkTransport.Init();
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
HostTopology topo = new HostTopology(cc, MAX_CONNECTION);
hostId = NetworkTransport.AddHost(topo);
connectionId = NetworkTransport.Connect(hostId, serverIPAdress, port, 0, out error);
isStarted = true;
isServer = false;
connectionTime = Time.time;
isStarted = true;
if (callback != null)
callback.Invoke();
Debug.Log("Client connected.");
}
private void Update()
{
if (!IsStarted)
return;
if (isServer)
serverLoop();
else
clientLoop();
}
private void serverLoop()
{
recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
switch (recData)
{
case NetworkEventType.Nothing: //1
break;
case NetworkEventType.ConnectEvent: //2
Debug.Log("Client " + connectionId + " has connected.");
break;
case NetworkEventType.DataEvent: //3
msg = Message.Deserialize(recBuffer);
Debug.Log("Client " + connectionId + " has sent : " + msg);
break;
case NetworkEventType.DisconnectEvent: //4
Debug.Log("Client " + connectionId + " has disconnected.");
break;
}
}
private void clientLoop()
{
recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
switch (recData)
{
case NetworkEventType.Nothing: //1
break;
case NetworkEventType.ConnectEvent: //2
break;
case NetworkEventType.DataEvent: //3
break;
case NetworkEventType.DisconnectEvent: //4
break;
}
}
public IEnumerator updatePlayerCount()
{
while (! IsStarted)
{
if (matchMaker != null)
matchMaker.ListMatches(0, 1, MATCH, false, 0, 0, OnMatchListCountPlayers);
yield return new WaitForSeconds(Simulation.Instance.InternetMatchRefreshRate);
}
yield break;
}
public void OnMatchListCountPlayers(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
{
if (!success)
throw new System.Exception("Match list failed : " + extendedInfo);
if (matches.Count == 0)
nPlayersOnline = 0;
else
nPlayersOnline = matches[0].currentSize;
}
public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
{
if (!success)
throw new System.Exception("Match list failed : " + extendedInfo);
if ((matches.Count == 0) || (matches[0].currentSize == 0))
createMatch();
else
{
Debug.Log("Joining match " + matches[0].name + " with " + matches[0].currentSize + " players in it, from a list of " + matches.Count + " matches.");
joinMatch(matches[0].networkId);
}
}
private void joinMatch(NetworkID id)
{
matchMaker.JoinMatch(id, MATCH, "", "", 0, 0, OnMatchJoined);
}
public void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (!success)
throw new System.Exception("Match join failed.");
currentMatch = matchInfo;
MatchInfo hostInfo = matchInfo;
isMatchCreator = false;
startClient(hostInfo.address);
}
private void OnApplicationQuit()
{
Debug.Log("On application quit");
if ((matchMaker != null) && (currentMatch != null))
matchMaker.DropConnection(currentMatch.networkId, currentMatch.nodeId, 0, (a, b) => { ; });
if ((IsMatchCreator) && (matchMaker != null))
matchMaker.DestroyMatch(currentMatch.networkId, 0, OnMatchDropConnection);
int i = 0;
while ((i < 10) && (!connectionDroped))
{
Thread.Sleep(100);
i++;
}
Destroy(matchMaker);
}
public void OnMatchDropConnection(bool success, string extendedInfo)
{
Debug.Log("Connection drop " + (success ? "success ! " : "falure ! ") + "extendedInfo = " + extendedInfo);
connectionDroped = true;
}
private void createMatch()
{
matchMaker.CreateMatch(MATCH, 10, true, MATCH, "", "", 0, 0, OnMatchCreate);
}
public void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (!success)
{
Debug.LogError("Match creation failed : " + extendedInfo);
Debug.LogError("Match info : " + matchInfo);
throw new System.Exception("Match creation failed : " + extendedInfo);
}
Debug.Log("on match create, server active = " + NetworkServer.active);
Debug.Log("matchInfo = " + matchInfo);
currentMatch = matchInfo;
isMatchCreator = true;
startServer();
}
}
}
Any help would be greatly appreciated !
Answer by _AkSeL_ · Jun 17, 2017 at 08:28 AM
The error is actually that two versions of the same project were connecting to the multiplayer service with the same ID. This should not raise an out of memory error but more something related to the ID used. Bug filed here : https://fogbugz.unity3d.com/default.asp?918528_iumo80ak8eo3ig1f
Your answer
![](https://koobas.hobune.stream/wayback/20220612123558im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unet Multiplayer Not working 1 Answer
UNET Matchmaking - Unable to force regions 0 Answers
Cannot start Matchmaking online game 0 Answers
Best solution for low bandwidth multiplayer game 1 Answer
How can i spawn my player in matchmaker using my UI? 0 Answers