Ejemplo n.º 1
0
        /// <summary>
        /// Send a message to a particular recipient.
        /// </summary>
        public void SendMessage(Message message)
        {
            if (recipients.ContainsKey(message.RecipientName))
            {
                Client client = recipients[message.RecipientName];

                client.EnqueueMessage(message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 这个类被发送者调用向客户端发送消息.
        /// </summary>
        /// <param name="message">新的消息</param>
        public void EnqueueMessage(Message message)
        {
            lock (messageQueue)
            {
                messageQueue.Enqueue(message);

                // 设置一个新的消息事件.
                messageEvent.Set();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method is called by a sender to send a message to this client.
        /// </summary>
        /// <param name="message">the new message</param>
        public void EnqueueMessage(Message message)
        {
            lock (messageQueue)
            {
                messageQueue.Enqueue(message);

                // Set a new message event.
                messageEvent.Set();
            }
        }
Ejemplo n.º 4
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            // 创建一个消息实体来包含所有必要数据.
            Message message = new Message();
            message.RecipientName = tbRecipientName.Text.Trim();
            message.MessageContent = tbMessageContent.Text.Trim();

            if (!string.IsNullOrWhiteSpace(message.RecipientName) && !string.IsNullOrEmpty(message.MessageContent))
            {
                // 调用客户端的适配器把消息立即发送到特定的接收端.
                ClientAdapter.Instance.SendMessage(message);

                // 显示时间戳.
                lbNotification.Text += DateTime.Now.ToLongTimeString() + ": 消息已发送!<br/>";
            }
        }