Exemplo n.º 1
0
        /// <summary>
        /// Send a command and returns the reply as a raw string
        /// </summary>
        /// <param name="command">The command to be sent</param>
        /// <returns>Returns the raw string replied by the server</returns>
        public virtual string SendRawCommand(TCCommand command)
        {
            string rawReply = "";

            canListen = false;

            lock (controlSocket)
            {
                //Send the command
                controlSocket.Send(command.Raw());

                //Wait for response
                int timeout = (int)ResponseTimeout / sleep;
                int i = 1;
                while (!controlSocket.ResponseAvailable && i < timeout)
                {
                    Thread.Sleep(sleep);
                    i++;
                }
                //Read Response

                rawReply = controlSocket.Receive();
            }

            canListen = true;

            return rawReply;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send a command and returns all replies
        /// </summary>
        /// <param name="command">The command to be sent</param>
        /// <returns>List of all received replies</returns>
        public virtual List<Reply> SendCommand(TCCommand command)
        {
            _controlSocket.Send(command.Raw());

            List<Reply> replies = new List<Reply>();

            // receive replies until we get an end reply
            for (;;)
            {
                lock (_replyBuffer)
                {
                    while (_replyBuffer.Count > 0)
                    {
                        Reply reply = _replyBuffer.Dequeue();
                        replies.Add(reply);
                        if (reply.RawString[3] == ' ')
                        {
                            // end reply received --> finished
                            return replies;
                        }
                    }
                }
            #if DEBUG
                if (!_replyReceivedHdl.WaitOne())
            #else
                if(!_replyReceivedHdl.WaitOne((int)ResponseTimeout))
            #endif
                {
                    throw new TimeoutException("Timeout while receiving replies");
                }
            }
        }