Esempio n. 1
0
        /// <summary>
        /// Datas the received handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        private void DataReceivedHandler(object sender, Hazel.DataReceivedEventArgs args)
        {
            Connection connection = (Connection)sender;

            Console.WriteLine("Received (" + string.Join <byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
            Console.WriteLine("SendType: " + args.Bytes.GetValue(0).ToString());
            //Console.WriteLine(((byte)SendType.SENDTOALL).ToString());

            //Create Struct ClientMessageReceived
            ClientMessageReceived NewClientConnected;

            NewClientConnected.ClientConnected   = connection;
            NewClientConnected.MessageBytes      = args.Bytes;
            NewClientConnected.SOClientConnected = args.SendOption;

            //Add To main Queue
            QueueMessages.Enqueue(NewClientConnected);
            ThreadPool.QueueUserWorkItem(Server.ConsumerThread);
            args.Recycle();
        }
Esempio n. 2
0
        private static void DataReceivedHandler(object sender, Hazel.DataReceivedEventArgs args)
        {
            Connection  conn   = (Connection)sender;
            HazelReader reader = new HazelReader(args.Bytes);

            byte header = reader.ReadByte();

            if (!userByConnection.ContainsKey(conn) && header > 2)
            {
                return;
            }
            if (userByConnection[conn].name == null && header > 3)
            {
                return;
            }

            if (DataHandlers.ContainsKey(header))
            {
                DataHandlers [header] (conn, reader);
            }

            args.Recycle();
        }