Hello
I have a problem with disconnecting connections once I try to remove the disconnected connection from the NetworkConnection list or native NetworkConnection list I encounter with the Out of index error in the server side .
this is my code.
if (_connections.Count > 0)
{
for (int i = 0; i < _connections.Count; i++)
{
DataStreamReader ServerStream;
NetworkEvent.Type cmd;
while ((cmd = _serverDrive.PopEventForConnection(_connections[i], out ServerStream))
!= NetworkEvent.Type.Empty)
{
if (cmd == NetworkEvent.Type.Connect)
{
}
else if (cmd == NetworkEvent.Type.Data)
{
}
else if (cmd == NetworkEvent.Type.Disconnect)/////////
{
_connections.RemoveAt(i);
// i--;
if (i > _connections.Count) break;
}
}
}
when I remove the " _connections.RemoveAt(i);" the error will not display.
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0
at ServerCode.Update () [0x001eb] in <cfbe4c1cbbe34153a2dc6d0d3c1177cb>:0