本文整理汇总了C#中NetMQ.Sockets.RouterSocket.SkipFrame方法的典型用法代码示例。如果您正苦于以下问题:C# RouterSocket.SkipFrame方法的具体用法?C# RouterSocket.SkipFrame怎么用?C# RouterSocket.SkipFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Sockets.RouterSocket
的用法示例。
在下文中一共展示了RouterSocket.SkipFrame方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasInTest
public void HasInTest()
{
using (var server = new RouterSocket())
using (var client = new DealerSocket())
{
var port = server.BindRandomPort("tcp://*");
// no one sent a message so it should be false
Assert.IsFalse(server.HasIn);
client.Connect("tcp://localhost:" + port);
// wait for the client to connect
Thread.Sleep(100);
// now we have one client connected but didn't send a message yet
Assert.IsFalse(server.HasIn);
client.SendFrame("1");
// wait for the message to arrive
Thread.Sleep(100);
// the has in should indicate a message is ready
Assert.IsTrue(server.HasIn);
server.SkipFrame(); // identity
string message = server.ReceiveFrameString();
Assert.AreEqual(message, "1");
// we read the message, it should false again
Assert.IsFalse(server.HasIn);
}
}
示例2: AddSocketDuringWork
public void AddSocketDuringWork()
{
using (var router1 = new RouterSocket())
using (var router2 = new RouterSocket())
using (var dealer1 = new DealerSocket())
using (var dealer2 = new DealerSocket())
using (var poller = new NetMQPoller { router1 })
{
int port1 = router1.BindRandomPort("tcp://127.0.0.1");
int port2 = router2.BindRandomPort("tcp://127.0.0.1");
dealer1.Connect("tcp://127.0.0.1:" + port1);
dealer2.Connect("tcp://127.0.0.1:" + port2);
bool router1Arrived = false;
bool router2Arrived = false;
var signal1 = new ManualResetEvent(false);
var signal2 = new ManualResetEvent(false);
router1.ReceiveReady += (s, e) =>
{
router1.SkipFrame();
router1.SkipFrame();
router1Arrived = true;
poller.Add(router2);
signal1.Set();
};
router2.ReceiveReady += (s, e) =>
{
router2.SkipFrame();
router2.SkipFrame();
router2Arrived = true;
signal2.Set();
};
poller.RunAsync();
dealer1.SendFrame("1");
Assert.IsTrue(signal1.WaitOne(300));
dealer2.SendFrame("2");
Assert.IsTrue(signal2.WaitOne(300));
poller.Stop();
Assert.IsTrue(router1Arrived);
Assert.IsTrue(router2Arrived);
}
}
示例3: RemoveTimer
public void RemoveTimer()
{
using (var router = new RouterSocket())
using (var dealer = new DealerSocket())
using (var poller = new NetMQPoller { router })
{
int port = router.BindRandomPort("tcp://127.0.0.1");
dealer.Connect("tcp://127.0.0.1:" + port);
bool timerTriggered = false;
var timer = new NetMQTimer(TimeSpan.FromMilliseconds(100));
timer.Elapsed += (s, a) => { timerTriggered = true; };
// The timer will fire after 100ms
poller.Add(timer);
bool messageArrived = false;
router.ReceiveReady += (s, e) =>
{
router.SkipFrame();
router.SkipFrame();
messageArrived = true;
// Remove timer
poller.Remove(timer);
};
poller.RunAsync();
Thread.Sleep(20);
dealer.SendFrame("hello");
Thread.Sleep(300);
poller.Stop();
Assert.IsTrue(messageArrived);
Assert.IsFalse(timerTriggered);
}
}
示例4: SimpleTimer
public void SimpleTimer()
{
// TODO it is not really clear what this test is actually testing -- maybe split it into a few smaller tests
using (var router = new RouterSocket())
using (var dealer = new DealerSocket())
using (var poller = new NetMQPoller { router })
{
int port = router.BindRandomPort("tcp://127.0.0.1");
dealer.Connect("tcp://127.0.0.1:" + port);
bool messageArrived = false;
router.ReceiveReady += (s, e) =>
{
Assert.IsFalse(messageArrived);
router.SkipFrame();
router.SkipFrame();
messageArrived = true;
};
bool timerTriggered = false;
int count = 0;
const int timerIntervalMillis = 100;
var timer = new NetMQTimer(TimeSpan.FromMilliseconds(timerIntervalMillis));
timer.Elapsed += (s, a) =>
{
// the timer should jump before the message
Assert.IsFalse(messageArrived);
timerTriggered = true;
timer.Enable = false;
count++;
};
poller.Add(timer);
poller.RunAsync();
Thread.Sleep(150);
dealer.SendFrame("hello");
Thread.Sleep(300);
poller.Stop();
Assert.IsTrue(messageArrived);
Assert.IsTrue(timerTriggered);
Assert.AreEqual(1, count);
}
}
示例5: AddTwoSocketAfterRemoving
public void AddTwoSocketAfterRemoving()
{
using (var router1 = new RouterSocket())
using (var router2 = new RouterSocket())
using (var router3 = new RouterSocket())
using (var router4 = new RouterSocket())
using (var dealer1 = new DealerSocket())
using (var dealer2 = new DealerSocket())
using (var dealer3 = new DealerSocket())
using (var dealer4 = new DealerSocket())
using (var poller = new NetMQPoller { router1, router2 })
{
int port1 = router1.BindRandomPort("tcp://127.0.0.1");
int port2 = router2.BindRandomPort("tcp://127.0.0.1");
int port3 = router3.BindRandomPort("tcp://127.0.0.1");
int port4 = router4.BindRandomPort("tcp://127.0.0.1");
dealer1.Connect("tcp://127.0.0.1:" + port1);
dealer2.Connect("tcp://127.0.0.1:" + port2);
dealer3.Connect("tcp://127.0.0.1:" + port3);
dealer4.Connect("tcp://127.0.0.1:" + port4);
int router1Arrived = 0;
int router2Arrived = 0;
bool router3Arrived = false;
bool router4Arrived = false;
var signal1 = new ManualResetEvent(false);
var signal2 = new ManualResetEvent(false);
var signal3 = new ManualResetEvent(false);
var signal4 = new ManualResetEvent(false);
router1.ReceiveReady += (s, e) =>
{
router1Arrived++;
router1.SkipFrame(); // identity
router1.SkipFrame(); // message
poller.Remove(router1);
signal1.Set();
};
router2.ReceiveReady += (s, e) =>
{
router2Arrived++;
router2.SkipFrame(); // identity
router2.SkipFrame(); // message
if (router2Arrived == 1)
{
poller.Add(router3);
poller.Add(router4);
signal2.Set();
}
};
router3.ReceiveReady += (s, e) =>
{
router3.SkipFrame(); // identity
router3.SkipFrame(); // message
router3Arrived = true;
signal3.Set();
};
router4.ReceiveReady += (s, e) =>
{
router4.SkipFrame(); // identity
router4.SkipFrame(); // message
router4Arrived = true;
signal4.Set();
};
poller.RunAsync();
dealer1.SendFrame("1");
Assert.IsTrue(signal1.WaitOne(300));
dealer2.SendFrame("2");
Assert.IsTrue(signal2.WaitOne(300));
dealer3.SendFrame("3");
dealer4.SendFrame("4");
dealer2.SendFrame("2");
dealer1.SendFrame("1");
Assert.IsTrue(signal3.WaitOne(300));
Assert.IsTrue(signal4.WaitOne(300));
poller.Stop();
router1.SkipFrame();
bool more;
Assert.AreEqual("1", router1.ReceiveFrameString(out more));
Assert.IsFalse(more);
Assert.AreEqual(1, router1Arrived);
Assert.AreEqual(2, router2Arrived);
Assert.IsTrue(router3Arrived);
Assert.IsTrue(router4Arrived);
}
}
示例6: AddSocketDuringWork
public void AddSocketDuringWork()
{
using (var router1 = new RouterSocket())
using (var router2 = new RouterSocket())
using (var dealer1 = new DealerSocket())
using (var dealer2 = new DealerSocket())
using (var poller = new Poller(router1) { PollTimeout = TestPollTimeoutMillis })
{
int port1 = router1.BindRandomPort("tcp://127.0.0.1");
int port2 = router2.BindRandomPort("tcp://127.0.0.1");
dealer1.Connect("tcp://127.0.0.1:" + port1);
dealer2.Connect("tcp://127.0.0.1:" + port2);
bool router1Arrived = false;
bool router2Arrived = false;
var signal1 = new ManualResetEvent(false);
var signal2 = new ManualResetEvent(false);
router1.ReceiveReady += (s, e) =>
{
router1.SkipFrame();
router1.SkipFrame();
router1Arrived = true;
poller.AddSocket(router2);
signal1.Set();
};
router2.ReceiveReady += (s, e) =>
{
router2.SkipFrame();
router2.SkipFrame();
router2Arrived = true;
signal2.Set();
};
poller.PollTillCancelledNonBlocking();
dealer1.SendFrame("1");
Assert.IsTrue(signal1.WaitOne(300));
dealer2.SendFrame("2");
Assert.IsTrue(signal1.WaitOne(300));
poller.CancelAndJoin();
Assert.IsTrue(router1Arrived);
Assert.IsTrue(router2Arrived);
}
}