Esempio n. 1
0
        private void ProcessOnDataArrival(string incomingCommand)
        {
            // reset heartbeat
            DisableHeartbeat();
            EnableHeartbeat();

            SocketCommand commandToProcess = new SocketCommand();

            // split..?
            string[] stringSeperators = new string[] { "<msg>" };
            string[] myCommands       = incomingCommand.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries);

            foreach (string command in myCommands)
            {
                try
                {
                    commandToProcess = TcpIpCommon.DeserializeCommandObject(command);
                }
                catch (Exception ex)
                {
                    // log here?
                    Debug.Print(ex.ToString());
                    //LogAccess.WriteLog("Error processing command: " + ex.ToString(), "Talker");
                    //throw;
                }

                if (commandToProcess != null)
                {
                    //SendAcknowledgement(commandToProcess.CommandID);
                    OnDataArrival(commandToProcess, _identifier);
                }
            }
        }
Esempio n. 2
0
        // private routines
        private void SendHeartBeat(AsyncSkt SocketToSendOn)
        {
            //disable the heartbeat so we don't get queued events
            DisableHeartbeat(); // _heartbeatTimer.Enabled = false;
            SocketCommand myHeartBeat = new SocketCommand()
            {
                ID        = TcpIpCommon.GetMyID(),
                Timestamp = DateTime.Now,
                //Command = CommandType.Heartbeat
            };

            //LogAccess.WriteLog("...heartbeat...", "Talker");
            SendData(myHeartBeat, SocketToSendOn);
            //re enable the timer so we can send future heartbeats
            EnableHeartbeat(); // _heartbeatTimer.Enabled = true;
        }
Esempio n. 3
0
        private bool SendData(SocketCommand CommandObjectToSend, AsyncSkt ConnectionToUse)
        {
            // do we have a valid connection?
            if (ConnectionToUse == null)
            {
                return(false);
            }

            // do we have an object to send?
            if (CommandObjectToSend == null)
            {
                return(false);
            }

            string SerializedData = "";

            try
            {
                SerializedData = TcpIpCommon.SerializeCommandObject(CommandObjectToSend);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog("Error serializing data in SendData: " + ex.ToString(), "Talker");
            }

            // (bsk) add divider for splitting...
            SerializedData += "<msg>";

            try
            {
                ConnectionToUse.SendData(SerializedData);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog("Error sending data: " + ex.ToString(), "Talker");
            }
            //LogAccess.WriteLog("SendData complete", "Talker");
            return(true);
        }
Esempio n. 4
0
        public bool Talk(SocketCommand CommandToSend)
        {
            //disable the heartbeat so we don't get a heartbeat while trying to send a command
            DisableHeartbeat(); // _heartbeatTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
            // update ID, timestamp
            CommandToSend.ID        = TcpIpCommon.GetMyID();
            CommandToSend.Timestamp = DateTime.Now;

            try
            {
                SendData(CommandToSend, _socketTalker);
                return(true);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog(ex.ToString(), "Talker");
                return(false);
            }
            finally
            {
                //re enable the timer so we can send future heartbeats
                EnableHeartbeat(); // _heartbeatTimer.Change(_heartbeatInterval,_heartbeatInterval);
            }
        }