Esempio n. 1
0
        public void SendMessages()
        {
            while (true)
            {
                while (!PStorage.isEmpty())
                {
                    var message = PStorage.getNext();

                    if (message != null)
                    {
                        var connections = Connections.GetConnInfosByCategory(message.newsCategory);

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

                            connection.Socket.Send(data);
                            Thread.Sleep(500);
                        }
                    }
                }

                Thread.Sleep(3000);
            }
        }
Esempio n. 2
0
        public static void Handle(byte[] payloadbytes, ConnInfo connInfo)
        {
            var payloadString = Encoding.UTF8.GetString(payloadbytes);

            if (payloadString.StartsWith("#"))
            {
                connInfo.newsCategory = payloadString.Split("#").LastOrDefault();
                Connections.Add(connInfo);
            }
            else
            {
                PHandler pHandler = JsonConvert.DeserializeObject <PHandler>(payloadString);
                PStorage.Add(pHandler);
            }

            Console.WriteLine(payloadString);
        }