//public void PacketSendHandler()
        //{
        //    while (serverInstance != null)
        //    {
        //        while(queuedSendPackets.Count <= 0)
        //        {
        //            Thread.Sleep(5);
        //        }

        //        foreach(KeyValuePair<Packet,NetworkPlayer> entry in queuedSendPackets)
        //        {
        //            SendPacket(entry.Value, entry.Key,true);
        //            queuedSendPackets.Remove(entry.Key);
        //        }
        //    }
        //}

        //public void QueueSendPacket(Packet pack, NetworkPlayer player)
        //{
        //    queuedSendPackets.Add(pack, player);
        //}


        public void UDPHandler()
        {
            try
            {
                while (udpListener != null)
                {
                    Packet recieved = udpListener.Recieve();
                    //Debug.Log("Recieved Packet: " + recieved.Key.udpEndpoint.ToString() + ", " + recieved.Value.packetType);
                    UnityPacketHandler.instance.QueuePacket(recieved);
                    udpListener.SendPacket(recieved, true);
                }
            } catch (System.Exception e)
            {
                if (e.ToString().Contains("ThreadAbort"))
                {
                    Debug.Log("NetServer.UDPHandler has stopped.");
                }
            }
        }