Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Random rand = new Random(50);

            using (var pubSocket = new PublisherSocket())
            {
                Console.WriteLine("Publisher socket binding...");
                pubSocket.Options.SendHighWatermark = 1000;
                pubSocket.Bind("tcp://localhost:12345");

                for (var i = 0; i < 100; i++)
                {
                    var randomizedTopic = rand.NextDouble();
                    if (randomizedTopic > 0.5)
                    {
                        var msg = "TopicA msg-" + i;
                        Console.WriteLine("Sending message : {0}", msg);
                        pubSocket.SendMoreFrame("TopicA").SendFrame(msg);
                    }
                    else
                    {
                        var msg = "TopicB msg-" + i;
                        Console.WriteLine("Sending message : {0}", msg);
                        pubSocket.SendMoreFrame("TopicB").SendFrame(msg);
                    }

                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sender");

            var publisherSocket = new PublisherSocket();

            publisherSocket.Connect(Settings.BROKER_IP, Settings.BROKER_PORT);

            if (publisherSocket.IsConnected)
            {
                while (true)
                {
                    var payload = new Payload();

                    Console.WriteLine("Enter the topic: ");
                    payload.Topic = Console.ReadLine().ToLower();

                    Console.Write("Enter the message: ");
                    payload.Message = Console.ReadLine();

                    var    payloadString = JsonConvert.SerializeObject(payload);
                    byte[] data          = Encoding.UTF8.GetBytes(payloadString);

                    publisherSocket.Send(data);
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("It's me Publisher ");

            var publisherSocket = new PublisherSocket();

            // noi vom utliza o librarie comuna utilizata si de sender si broker, publicher,
            // in caz de e schimbata adresa la broker sa nu fie nevoie sa schimbam si la sender si publisher in toate proiectele
            publisherSocket.Connect(Settings.BROKER_IP, Settings.BROKER_PORT);

            if (publisherSocket.IsConnected)
            {
                while (true)
                {
                    var payload = new Payload();

                    // noi citim de la tastatura mesajele si topicurile
                    Console.Write("What is the Topic :");
                    payload.Topic = Console.ReadLine().ToLower();

                    Console.Write("What is the Message :");
                    payload.Message = Console.ReadLine();

                    var    payloadString = JsonConvert.SerializeObject(payload);
                    byte[] data          = Encoding.UTF8.GetBytes(payloadString);

                    publisherSocket.Send(data);
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (var pubSocket = new PublisherSocket())
            {
                // 미해결 메시지 제한
                pubSocket.Options.SendHighWatermark = 1000;

                // 바인딩
                pubSocket.Bind("tcp://*:12345");

                for (var i = 0; i < 100; i++)
                {
                    if (i % 2 == 0)
                    {
                        var msg = "TopicA msg-" + i + " 노석수 바보";
                        Console.WriteLine($"Sending message : {msg}");
                        pubSocket.SendMoreFrame("TopicA").SendFrame(msg);
                    }
                    else
                    {
                        var msg = "TopicB msg-" + i + " 노석수 천재";
                        Console.WriteLine($"Sending message : {msg}");
                        pubSocket.SendMoreFrame("TopicB").SendFrame(msg);
                    }

                    Thread.Sleep(1000);
                }
            }
        }
        static void Main(string[] args)
        {
            var    values   = ret_varaibles();
            int    DELAY    = values.Item1;
            string IP       = values.Item2;
            string PORT     = values.Item3;
            string PROTOCOL = values.Item4;

            Console.WriteLine("\nRPC Stream Information:\n");
            Console.WriteLine("\tRPC Stream State: Active");
            Console.WriteLine("\tHost IP Address: " + PROTOCOL + "://" + IP + ":" + PORT);
            Console.WriteLine("\tDelay: " + DELAY + "ms\n");

            using (var pubSocket = new PublisherSocket())
            {
                MMDeviceEnumerator enumerator    = new MMDeviceEnumerator();
                MMDevice           defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
                // pubSocket.Options.SendHighWatermark = 0;
                pubSocket.Bind(PROTOCOL + "://" + IP + ":" + PORT);

                string new_command = "A";
                while (true)
                {
                    double result = defaultDevice.AudioMeterInformation.MasterPeakValue;
                    byte[] volume = BitConverter.GetBytes(result);
                    new_thread(new_command, volume, pubSocket);
                    Thread.Sleep(DELAY);
                }
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Publisher");

            var publisherSocket = new PublisherSocket();

            publisherSocket.Connect("127.0.0.1", 9999);

            if (publisherSocket.isConnected)
            {
                while (true)
                {
                    for (i = 0; i < 3; i++)
                    {
                        XmlDocument rssXmlDoc = new XmlDocument();

                        // Load the RSS file from the RSS URL
                        rssXmlDoc.Load(urlStr[i]);

                        // Parse the Items in the RSS file
                        XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");


                        var newsArr = new List <string>();


                        // Iterate through the items in the RSS file
                        int count = 0;
                        foreach (XmlNode rssNode in rssNodes)
                        {
                            count++;
                            XmlNode rssSubNode = rssNode.SelectSingleNode("title");
                            title = rssSubNode != null ? rssSubNode.InnerText : "";

                            rssSubNode  = rssNode.SelectSingleNode("description");
                            description = rssSubNode != null ? rssSubNode.InnerText : "";

                            rssSubNode = rssNode.SelectSingleNode("pubDate");
                            dateRaw    = rssSubNode != null ? rssSubNode.InnerText : "";
                            if (dateRaw != null)
                            {
                                date = dateRaw.Substring(dateRaw.Length - 24, 20);
                            }


                            newsArr.Add(date + "\n" + title + "\n" + description);


                            if (count == 3)
                            {
                                break;
                            }
                        }



                        //Console.WriteLine("Enter the topic:");
                        //phandler.newsCategory = Console.ReadLine().ToLower();
                        //Console.WriteLine("Enter the message:");
                        foreach (string aux in newsArr)
                        {
                            var phandler = new PHandler();
                            if (i == 0)
                            {
                                phandler.newsCategory = "news";
                            }
                            else if (i == 1)
                            {
                                phandler.newsCategory = "sport";
                            }
                            else
                            {
                                phandler.newsCategory = "tech";
                            }
                            phandler.newsDate = aux.Substring(0, aux.IndexOf("\n"));
                            phandler.newsBody = aux.Substring(aux.IndexOf("\n") + 1);
                            var loadString = JsonConvert.SerializeObject(phandler);

                            byte[] data = Encoding.UTF8.GetBytes(loadString);

                            publisherSocket.Send(data);
                            Thread.Sleep(1000);
                        }
                    }


                    Thread.Sleep(60000);
                }
            }



            Console.ReadLine();
        }
 static void new_thread(string new_command, byte[] volume, PublisherSocket pubSocket)
 {
     pubSocket.SendMoreFrame(new_command).SendFrame(volume);
 }