Пример #1
0
        public void DoSendMessaggeWork()
        {
            while (true)
            {
                while (!PayloadStorage.IsEmpty())
                {
                    var payload = PayloadStorage.GetNext();

                    if (payload != null)
                    {
                        var connections = ConnectionsStorage.GetConnectionsByTopic(payload.Topic);

                        foreach (var connection in connections)
                        {
                            var    payloadString = JsonConvert.SerializeObject(payload);
                            byte[] data          = Encoding.UTF8.GetBytes(payloadString);

                            connection.Socket.Send(data);
                        }
                    }
                }

                Thread.Sleep(TIME_TO_SLEEP);
            }
        }
Пример #2
0
        public void DoSendTopicWork()
        {
            while (true)
            {
                while (!PayloadStorage.IsEmpty() && ConnectionsStorage.ExistConnections() &&
                       (ConnectionsStorage.GetConnectionsByTopic(PayloadStorage.CheckNextTopic()).Count != 0 || PayloadStorage.CheckNextTopic() == "publisher-end"))
                {
                    var payload = PayloadStorage.GetNext();

                    if (payload != null)
                    {
                        var connections = ConnectionsStorage.GetConnectionsByTopic(payload.topic);
                        if (payload.type == "end")
                        {
                            connections = ConnectionsStorage.GetConnections();
                        }

                        foreach (var connection in connections)
                        {
                            var    payloadString = JsonConvert.SerializeObject(payload);
                            byte[] data          = Encoding.UTF8.GetBytes(payloadString);
                            Console.WriteLine(payloadString);
                            connection.Socket.Send(data);
                        }
                    }
                }
                Thread.Sleep(TIME_TO_SLEEP);
            }
        }