Example #1
0
        private void OnMessageReceived(object sender, EventArgs eventArgs)
        {
            double dTime = (double)swCommTimer.ElapsedTicks / Stopwatch.Frequency * 1000D;

            CommReceiveTime = dTime;
            SixMsg oSixMsg = (SixMsg)sender;

            conqSixMsgs.Enqueue(oSixMsg);
            areNewSixMessage.Set();
            swCommTimer.Restart();
        }
Example #2
0
        private void ReadCallback(IAsyncResult ar)
        {
            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            // Read data from the client socket.
            int bytesRead = 0;

            try
            {
                bytesRead = handler.EndReceive(ar);
            }
            catch (ObjectDisposedException ex)
            {
            }
            catch (Exception ex)
            {
                LogWriter.Instance.WriteToLog(ex.Message);
            }
            if (bytesRead > 0)
            {
                SixMsg temp = new SixMsg();
                temp.FillFromArray(state.buffer);
                if (temp.Header != 0)
                {
                    evCommandReceived.Raise(temp);
                }
            }
            if (!IsClosing)
            {
                try
                {
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                         ReadCallback, state);
                }
                catch (ObjectDisposedException e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Example #3
0
        private void Receive()
        {
            int iLenght = 0;

            while (!_StopListening)
            {
                if (listener.Available > 0)
                {
                    iLenght = listener.Receive(by1ReceivedMessage);
                    if (iLenght == by1ReceivedMessage.Length)
                    {
                        SixMsg temp = new SixMsg();
                        temp.FillFromArray(by1ReceivedMessage);
                        evCommandReceived.Raise(temp);
                        //evCommandReceived.Raise(by1ReceivedMessage.SixMsgFromByteArr());
                    }
                }
            }
        }