public void ErrorCodeTest() { using (var req = new RequestSocket()) using (var rep = new ResponseSocket()) using (var monitor = new NetMQMonitor(req, "inproc://rep.inproc", SocketEvents.ConnectDelayed)) { var eventArrived = false; monitor.ConnectDelayed += (s, a) => { eventArrived = true; }; monitor.Timeout = TimeSpan.FromMilliseconds(100); var monitorTask = Task.Factory.StartNew(monitor.Start); var port = rep.BindRandomPort("tcp://127.0.0.1"); req.Connect("tcp://127.0.0.1:" + port); req.SendFrame("a"); rep.SkipFrame(); rep.SendFrame("b"); req.SkipFrame(); Thread.Sleep(200); Assert.IsTrue(eventArrived); monitor.Stop(); Thread.Sleep(200); Assert.IsTrue(monitorTask.IsCompleted); } }
public void SendingTwoRequestsInaRow() { using (var rep = new ResponseSocket()) using (var req = new RequestSocket()) { var port = rep.BindRandomPort("tcp://localhost"); req.Connect("tcp://localhost:" + port); req.SendFrame("Hi"); rep.SkipFrame(); Assert.Throws <FiniteStateMachineException>(() => req.SendFrame("Hi2")); } }
public void Monitoring() { var listeningEvent = new ManualResetEvent(false); var acceptedEvent = new ManualResetEvent(false); var connectedEvent = new ManualResetEvent(false); using (var rep = new ResponseSocket()) using (var req = new RequestSocket()) using (var poller = new Poller { PollTimeout = TestPollTimeoutMillis }) using (var repMonitor = new NetMQMonitor(rep, "inproc://rep.inproc", SocketEvents.Accepted | SocketEvents.Listening)) using (var reqMonitor = new NetMQMonitor(req, "inproc://req.inproc", SocketEvents.Connected)) { repMonitor.Accepted += (s, e) => acceptedEvent.Set(); repMonitor.Listening += (s, e) => listeningEvent.Set(); repMonitor.AttachToPoller(poller); int port = rep.BindRandomPort("tcp://127.0.0.1"); reqMonitor.Connected += (s, e) => connectedEvent.Set(); reqMonitor.AttachToPoller(poller); poller.PollTillCancelledNonBlocking(); req.Connect("tcp://127.0.0.1:" + port); req.SendFrame("a"); rep.SkipFrame(); rep.SendFrame("b"); req.SkipFrame(); Assert.IsTrue(listeningEvent.WaitOne(300)); Assert.IsTrue(connectedEvent.WaitOne(300)); Assert.IsTrue(acceptedEvent.WaitOne(300)); poller.CancelAndJoin(); } }
public void Monitoring() { using (var rep = new ResponseSocket()) using (var req = new RequestSocket()) using (var monitor = new NetMQMonitor(rep, $"inproc://rep.inproc", SocketEvents.Accepted | SocketEvents.Listening)) { var listening = false; var accepted = false; monitor.Accepted += (s, a) => { accepted = true; }; monitor.Listening += (s, a) => { listening = true; }; monitor.Timeout = TimeSpan.FromMilliseconds(100); var monitorTask = Task.Factory.StartNew(monitor.Start); Thread.Sleep(10); var port = rep.BindRandomPort("tcp://127.0.0.1"); req.Connect("tcp://127.0.0.1:" + port); req.SendFrame("a"); rep.SkipFrame(); rep.SendFrame("b"); req.SkipFrame(); Thread.Sleep(200); Assert.IsTrue(listening); Assert.IsTrue(accepted); monitor.Stop(); Thread.Sleep(200); Assert.IsTrue(monitorTask.IsCompleted); } }