Exemple #1
0
        private void BidiChat()
        {
            var syn = new System.Windows.Forms.Form();               //wow...I actually need a freaking form object instantiated here to get these timers to run on this thread -__-
            ISynchronizeInvoke synob = (ISynchronizeInvoke)syn;

            ClientMsgCache.ClientAdded(cType);
            GlobSyn.MsgFromClient(cType, CID, connection.RemoteEndPoint, "ClientSetup <EOF>");

            timKeepAlive = new System.Timers.Timer();
            timKeepAlive.SynchronizingObject = synob;
            timKeepAlive.Elapsed            += new ElapsedEventHandler(KeepAliveTO);
            timKeepAlive.Interval            = 1000 * 20; //at 20 seconds, 18 bytes per exchange, should be 2.3MB/month
            timKeepAlive.Start();

            timSendChk = new System.Timers.Timer();
            timSendChk.SynchronizingObject = synob;
            timSendChk.Elapsed            += new ElapsedEventHandler(GrabTransmissionInCache); //check for message to send every 100ms
            timSendChk.Interval            = 100;
            timSendChk.Start();

            timRecMsgEscape = new System.Timers.Timer();
            timRecMsgEscape.SynchronizingObject = synob;
            timRecMsgEscape.Elapsed            += new ElapsedEventHandler(recMsgTO);
            timRecMsgEscape.Interval            = 1000;

            connection.Blocking = false;

            try
            {
                while (true)
                {
                    string retstr = null;

                    do
                    {
                        Thread.Sleep(10);
                        retstr = ReceiveWholeMsg();
                    } while (retstr == null);

                    GlobSyn.MsgFromClient(cType, CID, connection.RemoteEndPoint, retstr);

                    timKeepAlive.Stop();
                    timKeepAlive.Interval = 20000;
                    timKeepAlive.Start();

                    //Thread.Sleep(100);  //take a lil break before blocking on another receive
                }
            }
            catch (Exception Ex)
            {
                if (connection != null)
                {
                    GlobSyn.Log("FAILED TCP Client Connection reading from " + connection.RemoteEndPoint.ToString() + Environment.NewLine + "~~See Exception: " + Ex.Message);
                }
            }
        }
Exemple #2
0
        private byte ThisConnectionSucks()
        {
            disposing = true;// don't let this thread call this thang more than once!
            ClientMsgCache.ClientRemoved(cType);
            GlobSyn.MsgFromClient(cType, CID, connection.RemoteEndPoint, "ClientKilled <EOF>");

            timKeepAlive.Stop();
            timRecMsgEscape.Stop();
            timSendChk.Stop();

            timKeepAlive.Dispose();
            timRecMsgEscape.Dispose();
            timSendChk.Dispose();

            SelfDestruct(this); //if I abort the thread I am running on...wat..wait BRAIN MELT??!?!? will this be reached? put abort afterwards...lesse
            connThread.Abort();

            return(1);
        }