예제 #1
0
    public void Update()
    {
        //process received messages
        {
            List <DataPackage> received = null;
            lock (receiveBuffer)
            {
                received = new List <DataPackage>(receiveBuffer);
                receiveBuffer.Clear();
            }

            for (int i = 0; i < networkListeners.Count; i++)
            {
                INetworkListener nl = networkListeners[i].Target as INetworkListener;
                if (nl == null)
                {
                    networkListeners.RemoveAt(i);
                    i--;
                }
                else
                {
                    foreach (DataPackage dp in received)
                    {
                        nl.OnDataReceived(dp);
                    }
                }
            }
        }

        if (!hasToken)
        {
            return;
        }

        while (queue.Count != 0)
        {
            DataPackage dp = queue[0];
            queue.RemoveAt(0);
            WriteAll(dp);
        }

        hasToken = false;
        Write(nextClient, new TokenChangePackage());
    }