예제 #1
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();
        }
예제 #2
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();
        }
예제 #3
0
        static void Main(string[] args)
        {
            ushort forwardId;

            socket.Bind(9001);
            socket.Connect("127.0.0.1", 9000); // conectare la broker
            Console.WriteLine("Publisher");

            string text = "";

            while (true)
            {
                if (socket.isConnected)
                {
                    string tempId = "";
                    Console.Write("Enter thematic id: "); // id-ul la care sa transmita brokerul mesajele
                    tempId = Console.ReadLine();

                    if (String.IsNullOrWhiteSpace(tempId))
                    {
                        continue;
                    }

                    try
                    {
                        forwardId = Convert.ToUInt16(tempId);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        continue;
                    }

                    Console.WriteLine("Please enter a message");
                    text = Console.ReadLine();
                    if (String.IsNullOrWhiteSpace(text))
                    {
                        continue;
                    }

                    byte[] message = Message.CreateMessage(text, forwardId); // aici pregatim datele in format binar

                    socket.Send(message);                                    // transmite mesaj la broker.
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            ushort forwardPort;

            socket.Connect("127.0.0.1", 9000); // conectare la broker
            Console.WriteLine("Publisher");

            string text = "";

            while (true)
            {
                if (socket.isConnected)
                {
                    string tempPort = "";
                    Console.Write("Enter Forward port: "); // porturile la care sa transmita brokerul mesajele
                    tempPort = Console.ReadLine();

                    if (String.IsNullOrWhiteSpace(tempPort))
                    {
                        continue;
                    }

                    forwardPort = Convert.ToUInt16(tempPort);

                    Console.WriteLine("Please enter a message");
                    text = Console.ReadLine();
                    if (String.IsNullOrWhiteSpace(text))
                    {
                        continue;
                    }

                    byte[] message = Message.CreateMessage(text, forwardPort); // aici pregatim datele in format binar

                    socket.Send(message);                                      // transmite mesaj la broker.
                }
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: HowardAx/PAD1
        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();
        }