Example #1
0
        void Listen()
        {
            while (true)
            {
                if (threadKillSignal)
                {
                    return;
                }

                Byte[] rawData = new Byte[Constants.Networking.MAX_PACKET_SIZE];
                Int32  bytes   = 0;
                try
                {
                    bytes = stream.Read(rawData, 0, rawData.Length);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }

                //Check if bytes == 0, if so, connection was dropped
                if (bytes == 0)
                {
                    server.ClientDisconnected(uid);
                    return;
                }

                String data = Encoding.UTF8.GetString(rawData, 0, bytes);
                HandlePacket(Packet.Parse(data));
            }
        }