Exemple #1
0
        //----------------------------------------------------------------------------
        //  Purpose:
        //      the thread that does the work
        //
        //  Notes:
        //      None
        //
        //----------------------------------------------------------------------------
        private void RunTCPIPThread()
        {
            DateTime   receiveTime   = DateTime.Now;
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(ConfigFile.mRNDOIP), (int)mTCPIPPortID);

            while (true == mRunThread)
            {
                try
                {
                    Socket reader = new Socket(AddressFamily.InterNetwork,
                                               SocketType.Stream,
                                               ProtocolType.Tcp);

                    Debug.WriteLine("New socket:" + mName);

                    reader.Connect(localEndPoint);
                    reader.ReceiveTimeout = 10;
                    reader.DontFragment   = true;

                    while ((true == mRunThread) && (true == reader.Connected))
                    {
                        try
                        {
                            mDataSize         = (UInt32)reader.Receive(mData, (int)RNDOMessage.MAX_FULL_MESSAGE_SIZE, SocketFlags.None);
                            mReceivedTimeSpan = DateTime.Now.Subtract(receiveTime);

                            // If we have data update the counts and labels.
                            if ((mDataSize < (int)ConfigFile.MAX_BUFFER_SIZE) && (mDataSize >= RNDOMessage.MAX_FULL_MESSAGE_SIZE))
                            {
                                mReceivedCount++;
                                receiveTime = DateTime.Now;

                                for (int index = 0; index < mDataSize; index += RNDOMessage.MAX_FULL_MESSAGE_SIZE)
                                {
                                    RNDOMessage NDOMess = new RNDOMessage(mData, index);

                                    for (int indexInner = 0; indexInner < mNDOMessages.Count; indexInner++)
                                    {
                                        if (NDOMess.GetHeader() == mNDOMessages[indexInner].GetHeader())
                                        {
                                            mNDOMessages[indexInner].SetData(NDOMess.GetData());
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("Inner Except:" + e.ToString());
                            Debug.WriteLine("Connection:" + reader.Connected.ToString());
                        }
                        Thread.Sleep(3);
                    }
                    reader.Close();
                }
                catch (Exception)
                {
                    Debug.WriteLine("Outer Except");
                }
                Thread.Sleep(3);
            }
        }
Exemple #2
0
        //----------------------------------------------------------------------------
        //  Purpose:
        //      the thread that does the work
        //
        //  Notes:
        //      None
        //
        //----------------------------------------------------------------------------
        private void RunAFDXThread()
        {
            DateTime oldReceiveTime = DateTime.Now;
            DateTime oldTime        = DateTime.Now;
            // Open up the receive TCP/IP port.
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, (int)mTCPIPReceivePortID);

            Socket listener = new Socket(AddressFamily.InterNetwork,
                                         SocketType.Stream,
                                         ProtocolType.Tcp);

            listener.Bind(localEndPoint);
            listener.Listen(20);
            listener.ReceiveTimeout = 9000;

            while (true == mRunThread)
            {
                try
                {
                    Socket client = listener.Accept();
                    oldTime = DateTime.Now;

                    while ((true == mRunThread) && (true == client.Connected))
                    {
                        try
                        {
                            mDataSize        = (UInt32)client.Receive(mData);
                            mReceiveTimeSpan = DateTime.Now.Subtract(oldReceiveTime);

                            if (0 != mDataSize)
                            {
                                oldReceiveTime = DateTime.Now;

                                for (int index = 0; index < mDataSize; index += RNDOMessage.MAX_FULL_MESSAGE_SIZE)
                                {
                                    RNDOMessage NDOMess = new RNDOMessage(mData, index);
                                    bool        found   = false;

                                    for (int indexInner = 0; indexInner < mMessages.Count; indexInner++)
                                    {
                                        if (NDOMess.GetHeader() == mMessages[indexInner].GetHeader())
                                        {
                                            mMessages[indexInner].SetData(NDOMess.GetData());
                                            found = true;
                                        }
                                    }

                                    if (false == found)
                                    {
                                        mMessages.Add(NDOMess);
                                    }
                                }
                            }
                            else
                            {
                                if (oldTime.AddSeconds(3) < DateTime.Now)
                                {
                                    break;
                                }
                            }
                            Thread.Sleep(3);
                        }
                        catch (Exception)
                        {
                        }
                        Thread.Sleep(3);
                    }
                    client.Close();
                }
                catch (Exception)
                {
                }
                Thread.Sleep(3);
            }

            for (int index = 0; index < mClientSockets.Count; index++)
            {
                try
                {
                    mClientSockets[index].Close();
                }
                catch (Exception)
                {
                }
            }
        }