Exemple #1
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 = "";

            SerializedData = TcpIpCommon.SerializeCommandObject(CommandObjectToSend);

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

            try
            {
                ConnectionToUse.SendData(SerializedData);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog("Error sending data: " + ex.ToString(), "Listener");
                //throw;
            }

            return(true);
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        // private routines
        private void SendHeartBeat(AsyncSkt SocketToSendOn)
        {
            SocketCommand myHeartBeat = new SocketCommand()
            {
                ID        = TcpIpCommon.GetMyID(),
                Timestamp = DateTime.Now,
                Command   = CommandType.Heartbeat
            };

            //LogAccess.WriteLog("...heartbeat...", "Listener");
            SendData(myHeartBeat, SocketToSendOn);
        }
Exemple #4
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;
        }
Exemple #5
0
        private void ProcessOnDataArrival(string incomingCommand)
        {
            SocketCommand incomingCommandObject = new SocketCommand();

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

            //LogAccess.WriteLog("Data arrival event", "Listener");
            foreach (string command in myCommands)
            {
                if (tracing)
                {
                    // we need to log the command with a timestamp
                    //TcpIpCommon.WriteToTraceLogSimple(command.ToString());
                }

                try
                {
                    incomingCommandObject = TcpIpCommon.DeserializeCommandObject(command);
                }
                catch (Exception ex)
                {
                    // log here?
                    //Debug.Print(ex.ToString());
                    //LogAccess.WriteLog(ex.ToString());
                    //LogAccess.WriteLog("Bad Command received: " + command.ToString(), "Listener");
                    incomingCommandObject = null;
                    //throw;
                }

                if (incomingCommandObject != null)
                {
                    SendAcknowledgement(incomingCommandObject.CommandID);
                    OnDataArrival(incomingCommandObject, _identifier);
                }
            }
        }
Exemple #6
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);
            }
        }