Exemplo n.º 1
0
        // Prepares data to be sent and calls sending method.
        // It can process large messages by cutting them into small ones.
        public void SendMessage(AsyncUserTokenBase token, Byte[] msgToSend)
        {
            // do not let sending simultaniously using the same Args object
            token.writeSemaphore.WaitOne();

            // pause keep-alive messages (will resume after sending)
            token.KeepAliveTimer.Stop();

            if (msgToSend.Length == 0)
            {
                Logger.WriteStr(" Going to send keep-alive message.");
            }
            else
            {
                Logger.WriteStr(" Going to send message with length=" + msgToSend.Length + ".");
            }

            // prepare data to send: add prefix that holds length of message
            Byte[] prefixToAdd = BitConverter.GetBytes(msgToSend.Length);

            // prepare complete data and store it into token
            token.SendingMsg = new Byte[MsgPrefixLength + msgToSend.Length];
            prefixToAdd.CopyTo(token.SendingMsg, 0);
            msgToSend.CopyTo(token.SendingMsg, MsgPrefixLength);

            StartSend(token.writeEventArgs);
        }
Exemplo n.º 2
0
        public void SendKeepAlive(object sender, EventArgs e)
        {
            AsyncUserTokenBase token = ((KeepAliveTimer)sender).Token;

            SendMessage(token, new byte[0]);
        }
Exemplo n.º 3
0
 public KeepAliveTimer(AsyncUserTokenBase token) : base()
 {
     Token    = token;
     Interval = 30000;  // 30 sec
     Enabled  = true;
 }