Ejemplo n.º 1
0
        /// <summary>
        /// The following function is in charge of trying to connect to the server.
        /// If it is connected, try to get messages from the server
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void TimerGetMessageFunction(Object source, ElapsedEventArgs e)
        {
            if (Connected)
            {
                string message = "";
                //will fail when server connection suddenly is lost
                try
                {
                    message = server.RetrieveMessage(comID);
                }
                catch
                {
                    //so server connection is lost, reset server
                    Server = null;
                    Debug.WriteLine("ERROR: Communication to server is lost");
                    return;
                }

                if (message.Length > 0)  //if there is a message
                {
                    if (message != "{}") //if there ARE messages
                    {
                        IncomingCommand_Handle(message);
                    }
                }
            }
            else
            {
                //try to connect...
                Connect();
            }
        }