Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var serverTread = new Thread(() =>
            {
                Log("Start server.");
                var _server = new ReliableServer("tcp://*:6669");

                var index = 0;

                while (true)
                {
                    var message = new NetMQMessage();
                    message.Append("A");
                    message.Append("hello: " + index);
                    message.Append("world");
                    _server.Publish(message);
                    Console.WriteLine("publishing: " + message);
                    Thread.Sleep(100);
                    index++;
                }
            });

            serverTread.Start();
            //		client_thread_.Start();

            //new SimpleClient().Run("tcp://localhost:6669");
            var clientTread = new Thread(() =>
            {
                Log("Start client.");
                var _client = new ReliableClient("tcp://localhost:6669");
                _client.Subscribe("A");

                while (true)
                {
                    NetMQMessage msg = null;
                    msg = _client.ReceiveMessage();
                    if (msg != null)
                    {
                        var topic   = msg.Pop().ConvertToString();
                        var message = msg.Pop().ConvertToString();
                        var output  = String.Format("reviced topic: {0}, message: {1}", topic, message);
                        Log(output);
                    }
                    Thread.Sleep(10);
                }
            });

            clientTread.Start();

            Console.ReadLine();
        }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        AsyncIO.ForceDotNet.Force();
        NetMQConfig.ManualTerminationTakeOver();
        NetMQConfig.ContextCreate(true);
        var _server_thread = new Thread(() =>
        {
            Log("Start server.");
            var _server = new ReliableServer("tcp://*:6669");

            var index = 0;

            while (true)
            {
                lock (_threadLock) {
                    if (_endThread)
                    {
                        break;
                    }
                }
                var message = new NetMQMessage();
                message.Append("A");
                message.Append("hello: " + index);
                _server.Publish(message);
                Log("publishing: " + message);
                Thread.Sleep(100);
                index++;
            }
            Log("close server.");
            _server.Dispose();
        });

        _server_thread.Start();

        var _client_thread = new Thread(() =>
        {
            Log("Start client.");
            var _client = new ReliableClient("tcp://localhost:6669");
            _client.Subscribe("A");

            while (true)
            {
                lock (_threadLock) {
                    if (_endThread)
                    {
                        break;
                    }
                }

                NetMQMessage msg = null;
                msg = _client.ReceiveMessage();
                if (msg != null)
                {
                    var topic   = msg.Pop().ConvertToString();
                    var message = msg.Pop().ConvertToString();
                    var output  = String.Format("reviced topic: {0}, message: {1}", topic, message);
                    Log(output);
                }
                Thread.Sleep(10);
            }
            Log("close client.");
            _client.Dispose();
        });

        _client_thread.Start();
    }