示例#1
0
        public void SimpleReqRep(string address)
        {
            using (var rep = new ResponseSocket())
                using (var req = new RequestSocket())
                {
                    var port = rep.BindRandomPort(address);
                    req.Connect(address + ":" + port);

                    req.SendFrame("Hi");

                    CollectionAssert.AreEqual(new[] { "Hi" }, rep.ReceiveMultipartStrings());

                    rep.SendFrame("Hi2");

                    CollectionAssert.AreEqual(new[] { "Hi2" }, req.ReceiveMultipartStrings());
                }
        }
示例#2
0
        public void SendMultipartMessage()
        {
            using (var rep = new ResponseSocket())
                using (var req = new RequestSocket())
                {
                    var port = rep.BindRandomPort("tcp://localhost");
                    req.Connect("tcp://localhost:" + port);

                    req.SendMoreFrame("Hello").SendFrame("World");

                    CollectionAssert.AreEqual(new[] { "Hello", "World" }, rep.ReceiveMultipartStrings());

                    rep.SendMoreFrame("Hello").SendFrame("Back");

                    CollectionAssert.AreEqual(new[] { "Hello", "Back" }, req.ReceiveMultipartStrings());
                }
        }
示例#3
0
        /// <summary>
        /// 三经典模式:请求响应
        /// </summary>
        static void ReqRep()
        {
            using (var rep = new ResponseSocket())
                using (var req = new RequestSocket())
                {
                    var port = rep.BindRandomPort(address);
                    req.Connect(address + ":" + port);

                    req.SendFrame("Hi");

                    Console.WriteLine(rep.ReceiveMultipartStrings().FirstOrDefault());

                    rep.SendFrame("Hi2");

                    Console.WriteLine(req.ReceiveMultipartStrings().FirstOrDefault());
                }
        }