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()); } }
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()); } }
/// <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()); } }