Example #1
0
        static void Main(string[] args)
        {
            // Definition of objects
            Nep.Node       node = new Nep.Node("csharp_sender");
            Nep.Subscriber sub  = node.new_sub("test", "json");

            // Message as strings to convert to Msg
            string msg   = "";
            bool   isMsg = false;

            // print message and finish
            while (!isMsg)
            {
                // Non blocking listen
                isMsg = sub.listenNB(ref msg);

                // if isMsg == true, then msg has information, otherwise, there is no message
                if (isMsg)
                {
                    // Convert JSON string to Msg
                    Msg message = JsonConvert.DeserializeObject <Msg>(msg);
                    Console.WriteLine(message.message);
                }
            }

            // See message 2 seconds
            Thread.Sleep(2000);
            // Close sockets
            sub.close();
            node.close();
        }
Example #2
0
        static void Main(string[] args)
        {
            // Definition of objects
            Nep.Node      node = new Nep.Node("csharp_sender");
            Nep.Publisher pub  = node.new_pub("test", "json");
            // Message to send
            Msg msg = new Msg();

            // Fill message
            msg.message = "hello";
            // Publish message
            pub.publish(msg);
            // Close sockets
            pub.close();
            node.close();
        }