示例#1
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);
                }
            }
        }
示例#2
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);
                }
            }
        }
        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);
                }
            }
        }
示例#4
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.
                }
            }
        }