Exemplo n.º 1
0
 void SocketConnected(object sender, SocketEventArgs e)
 {
     Interlocked.Increment(ref connections);
     ServerInstrumentation.Current.Connect();
     SocketAsyncEventArgs args = socketArgsPool.CheckOut();
     bufferManager.CheckOut(args);
     var connection = new ServerConnection(e.Socket, args,
         new DataReceivedCallback(DataReceived),
         new DisconnectedCallback(Disconnected));
 }
Exemplo n.º 2
0
 static void Disconnected(ServerConnection sender, SocketAsyncEventArgs e)
 {
     Interlocked.Decrement(ref connections);
     ServerInstrumentation.Current.Disconnect();
     bufferManager.CheckIn(e);
     socketArgsPool.CheckIn(e);
 }
Exemplo n.º 3
0
        static void HandleDataReceived(ServerConnection sender, DataEventArgs e)
        {
            /*
            Interlocked.Increment(ref currencies);

            byte[] temp = new byte[] { 0xAA, 0xBB, 0x00, 0x09, 0xA0, 0x0A, 0x00, 0x00, 0x00 };

            sender.SendData(temp, 0, temp.Length);

            return;
            */

            /**/

            byte[] datas = e.Data;
            Interlocked.Increment(ref messages);
            Interlocked.Add(ref bytes, datas.Length);

            var msg = Message.ConvertFrom(datas);
            //var line = e.Data.ToHexString();
            //File.AppendAllText("data.txt", line + Environment.NewLine);
            if (msg == null)
            {
                return;
            }

            if (msg.Datas == null)
            {
                msg.Datas = new byte[] { 0 };
            }

            byte flag = 0;

            if (msg.Type == (int)MessageType.Beep)
            {
                UpdateDeviceInfo(msg, e.Device);
            }

            else if (msg.Type == (int)MessageType.Login)
            {
                if (msg.Device == null)
                {
                    ServerInstrumentation.Current.LoginFailed();

                    if (!allowAllowAnonymous)
                    {
                        flag = 1;
                        sender.Disconnect();
                        return;
                    }
                }

                if (!allowAllowAnonymous || msg.Device != null)
                {
                    UpdateDeviceInfo(msg, e.Device);
                    sender.AuthorizationType = AuthorizationType.Authorized;
                }
            }

            else if (msg.Type == (int)MessageType.Detail)
            {
                Interlocked.Increment(ref currencies);

                if (!allowAllowAnonymous && sender.AuthorizationType == AuthorizationType.Anonymous)
                {
                    ServerInstrumentation.Current.Unregisted();

                    if (!allowAllowAnonymous)
                    {
                        sender.Disconnect();
                        return;
                    }
                }
                UpdateDeviceInfo(msg, e.Device);
                e.Device.Increate();
                if (msg.Currency != null)
                {
                    DataPool.Push(msg.Currency);
                }
            }

            else if (msg.Type == (int)MessageType.BlackTable)
            {

            }

            else if (msg.Type == (int)MessageType.DownLoadBlackTable)
            {

            }

            var data = msg.GetBytes(flag);
            sender.SendData(data, 0, data.Length);
        }
Exemplo n.º 4
0
 static void DataReceived(ServerConnection sender, DataEventArgs e)
 {
     try
     {
         HandleDataReceived(sender, e);
     }
     catch (Exception ex)
     {
         ElibExceptionHandler.Handle(ex as Exception);
     }
 }