Esempio n. 1
0
        /// <summary>
        ///     Called when data has been received by the socket.
        /// </summary>
        /// <param name="result">The asyncronous operation's result.</param>
        void ReadCallback(IAsyncResult result)
        {
            var msg = (MessageReader)result.AsyncState;

            try
            {
                msg.Length = socket.EndReceive(result);
            }
            catch (SocketException e)
            {
                msg.Recycle();
                Disconnect("Socket exception while reading data: " + e.Message);
                return;
            }
            catch (Exception)
            {
                msg.Recycle();
                return;
            }

            //Exit if no bytes read, we've failed.
            if (msg.Length == 0)
            {
                msg.Recycle();
                Disconnect("Received 0 bytes");
                return;
            }

            //Begin receiving again
            try
            {
                StartListeningForData();
            }
            catch (SocketException e)
            {
                Disconnect("Socket exception during receive: " + e.Message);
            }
            catch (ObjectDisposedException)
            {
                //If the socket's been disposed then we can just end there.
                return;
            }

            if (this.TestLagMs > 0)
            {
                Thread.Sleep(this.TestLagMs);
            }

            if (this.TestDropRate > 0)
            {
                if ((this.testDropCount++ % this.TestDropRate) == 0)
                {
                    return;
                }
            }

            DataReceivedRaw?.Invoke(msg.Buffer, msg.Length);
            HandleReceive(msg, msg.Length);
        }
Esempio n. 2
0
 private void OnDataReceived(string type, JObject data)
 {
     DataReceivedRaw?.Invoke(type, data);
 }
Esempio n. 3
0
 private void OnDataReceived(string type, dynamic data)
 {
     DataReceivedRaw?.Invoke(type, data);
 }