Пример #1
0
        private static void c_OnUnsolicitedMessage(object sender, ClientCommandEventArgs e)
        {
            MqttCommand command = e.Command;

            var p = command as Publish;
            if (p != null)
            {
                var sb = new StringBuilder();
                if (p.Header.Duplicate)
                {
                    sb.Append("!!! DUPLICATE !!! - ");
                }
                sb.AppendFormat("TOPIC: {0}", p.Topic);
                sb.AppendLine();
                foreach (char c in Encoding.ASCII.GetChars(p.Message))
                {
                    if (!char.IsControl(c))
                    {
                        sb.Append(c);
                    }
                }

                sb.AppendLine();
                var result = sb.ToString();

                lock (conLock)
                {
                    Console.WriteLine(result);
                }
            }
        }
Пример #2
0
        private void _broker_OnMessageReceived(object sender, ClientCommandEventArgs e)
        {
            MqttCommand command = e.Command;

            Debug.WriteLine("RECV: {0} ({1})", command.CommandMessage, command.MessageId);

            lock (_lastHeaderLock)
            {
                _lastHeard = DateTime.UtcNow;
            }

            switch (command.CommandMessage)
            {
                case CommandMessage.PUBACK:
                case CommandMessage.PUBCOMP:
                case CommandMessage.PUBREC:
                case CommandMessage.PUBREL:
                case CommandMessage.SUBACK:
                case CommandMessage.CONNACK:
                case CommandMessage.UNSUBACK:
                    _manager.Deliver(command);
                    break;
                case CommandMessage.PINGRESP:
                    // ignore (we sent it) - eventually track
                    break;
                default:
                    _manager.StartNew(command, Notify);
                    break;
            }
        }
Пример #3
0
        private void ClientOnMessageReceived(object sender, ClientCommandEventArgs e)
        {
            MqttCommand command = e.Command;
            Debug.WriteLine("{0} : Recevied Message {1} id {2}", DateTime.Now.ToString("o"), command.CommandMessage,
                            command.MessageId);

            switch (command.CommandMessage)
            {
                case CommandMessage.PUBACK:
                case CommandMessage.PUBCOMP:
                case CommandMessage.PUBREC:
                case CommandMessage.PUBREL:
                case CommandMessage.SUBACK:
                case CommandMessage.CONNACK:
                case CommandMessage.UNSUBACK:
                case CommandMessage.PINGRESP:
                    _manager.Deliver(command);
                    break;
                default:
                    _manager.StartNew(command, Notify);
                    break;
            }
        }
Пример #4
0
        void c_OnUnsolicitedMessage(object sender, ClientCommandEventArgs e)
        {
            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (nextUpdate > DateTime.UtcNow)
                {
                    return;
                }

                nextUpdate = DateTime.UtcNow.AddSeconds(1);

                MqttCommand command = e.Command;

                Publish p = command as Publish;
                if (p != null)
                {
                    lock (this.textBlock1)
                    {
                        if (p.Header.Duplicate)
                        {
                            this.textBlock1.Text = "!!! DUPLICATE !!! - ";
                        }

                        StringBuilder sb = new StringBuilder();

                        sb.AppendFormat("TOPIC: {0}", p.Topic);
                        sb.AppendLine();
                        sb.AppendLine();

                        foreach (char c in UTF8Encoding.UTF8.GetChars(p.Message))
                        {
                            if (!char.IsControl(c))
                            {
                                sb.Append(c);
                            }
                        }

                        sb.AppendLine();
                        sb.AppendLine();

                        this.textBlock1.Text = sb.ToString();
                    }
                }
            });
        }