예제 #1
0
		// Housekeeping
		protected void OnHeartBeatTimerCallback(object state)
		{
			if (this.ReadyState == WebSocketState.Open)
			{
				IMessage msg = new Heartbeat();
				try
				{
					if (this.outboundQueue != null && !this.outboundQueue.IsAddingCompleted)
					{
						this.outboundQueue.Add(msg.Encoded);
						if (this.HeartBeatTimerEvent != null)
						{
							this.HeartBeatTimerEvent.BeginInvoke(this, EventArgs.Empty, EndAsyncEvent, null);
						}
					}
				}
				catch(Exception ex)
				{
					// 
					Trace.WriteLine(string.Format("OnHeartBeatTimerCallback Error Event: {0}\r\n\t{1}", ex.Message, ex.InnerException));
				}
			}
		}
        // Housekeeping
        protected void OnHeartBeatTimerCallback(object state)
        {
            if (state != null)
            {
                this.OnErrorEvent(this, new ErrorEventArgs("heartbeat_timeout"));
                return;
            }

            if (this.ReadyState == WebSocketState.OPEN)
            {
                IMessage msg = new Heartbeat();
                try
                {
                    if (this.outboundQueue != null)
                    {
                        this.outboundQueue.Enqueue(msg.Encoded);
                        if (this.HeartBeatTimerEvent != null)
                        {
                            this.HeartBeatTimerEvent.BeginInvoke(this, EventArgs.Empty, EndAsyncEvent, null);
                        }
                        this.socketHeartBeatTimer.Change(HandShake.HeartbeatInterval, HandShake.HeartbeatInterval);
                    }
                }
                catch(Exception ex)
                {
                    //
                    Trace.WriteLine(string.Format("OnHeartBeatTimerCallback Error Event: {0}\r\n\t{1}", ex.Message, ex.InnerException));
                }
            }
        }