Пример #1
0
        /// <summary>
        ///     Handles incoming data on the pipe.
        ///     Feeds the data into an instance of JsonLineProtocol.
        ///     Loops over any packets that were decoded and sends them to Command
        /// </summary>
        private void Recv()
        {
            var recvBytes = new byte[256];
            var proto     = new JsonLineProtocol();

            Socket.Receive(recvBytes);

            var msgs = proto.Feed(Encoding.ASCII.GetString(recvBytes));

            foreach (var packet in msgs)
            {
                try
                {
                    Command(packet);
                }
                catch (TimeoutException)
                {
                    Socket = null;
                    OnDisconnect?.Invoke();
                    throw;
                }
                catch (SocketException ex)
                {
                    Socket = null;
                    OnDisconnect?.Invoke();
                    throw new ConnectionException("Connection is in an error state.", ex);
                }
            }
        }