本文整理汇总了C#中NetMQ.Sockets.RouterSocket.SendMoreFrame方法的典型用法代码示例。如果您正苦于以下问题:C# RouterSocket.SendMoreFrame方法的具体用法?C# RouterSocket.SendMoreFrame怎么用?C# RouterSocket.SendMoreFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Sockets.RouterSocket
的用法示例。
在下文中一共展示了RouterSocket.SendMoreFrame方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoMessagesFromRouterToDealer
public void TwoMessagesFromRouterToDealer()
{
using (var server = new RouterSocket())
using (var client = new DealerSocket())
using (var poller = new NetMQPoller { client })
{
var port = server.BindRandomPort("tcp://*");
client.Connect("tcp://127.0.0.1:" + port);
var cnt = 0;
client.ReceiveReady += (sender, e) =>
{
var strs = e.Socket.ReceiveMultipartStrings();
foreach (var str in strs)
{
Console.WriteLine(str);
}
cnt++;
if (cnt == 2)
{
poller.Stop();
}
};
byte[] clientId = Encoding.Unicode.GetBytes("ClientId");
client.Options.Identity = clientId;
const string request = "GET /\r\n";
const string response = "HTTP/1.0 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Hello, World!";
client.SendFrame(request);
byte[] serverId = server.ReceiveFrameBytes();
Assert.AreEqual(request, server.ReceiveFrameString());
// two messages in a row, not frames
server.SendMoreFrame(serverId).SendFrame(response);
server.SendMoreFrame(serverId).SendFrame(response);
poller.Run();
}
}
示例2: Mandatory
public void Mandatory()
{
using (var router = new RouterSocket())
{
router.Options.RouterMandatory = true;
router.BindRandomPort("tcp://*");
Assert.Throws<HostUnreachableException>(() => router.SendMoreFrame("UNKNOWN").SendFrame("Hello"));
}
}
示例3: Mandatory
public void Mandatory()
{
using (var router = new RouterSocket())
{
router.Options.RouterMandatory = true;
router.Bind("tcp://127.0.0.1:5555");
using (var dealer = new DealerSocket())
{
dealer.Options.Identity = Encoding.ASCII.GetBytes("1");
dealer.Connect("tcp://127.0.0.1:5555");
dealer.SendFrame("Hello");
Assert.AreEqual("1", router.ReceiveFrameString());
Assert.AreEqual("Hello", router.ReceiveFrameString());
}
Thread.Sleep(100);
Assert.Throws<HostUnreachableException>(() => router.SendMoreFrame("1").SendFrame("Hello"));
}
}
示例4: ReconnectOnRouterBug
public void ReconnectOnRouterBug()
{
{
using (var dealer = new DealerSocket())
{
dealer.Options.Identity = Encoding.ASCII.GetBytes("dealer");
dealer.Bind("tcp://localhost:6667");
using (var router = new RouterSocket())
{
router.Options.RouterMandatory = true;
router.Connect("tcp://localhost:6667");
Thread.Sleep(100);
router.SendMoreFrame("dealer").SendFrame("Hello");
var message = dealer.ReceiveFrameString();
Assert.That(message == "Hello");
router.Disconnect("tcp://localhost:6667");
Thread.Sleep(1000);
router.Connect("tcp://localhost:6667");
Thread.Sleep(100);
router.SendMoreFrame("dealer").SendFrame("Hello");
message = dealer.ReceiveFrameString();
Assert.That(message == "Hello");
}
}
}
}
示例5: RawSocket
public void RawSocket()
{
using (var router = new RouterSocket())
using (var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
router.Options.RouterRawSocket = true;
var port = router.BindRandomPort("tcp://127.0.0.1");
clientSocket.Connect("127.0.0.1", port);
clientSocket.NoDelay = true;
byte[] clientMessage = Encoding.ASCII.GetBytes("HelloRaw");
int bytesSent = clientSocket.Send(clientMessage);
Assert.Greater(bytesSent, 0);
byte[] id = router.ReceiveFrameBytes();
byte[] message = router.ReceiveFrameBytes();
router.SendMoreFrame(id).SendMoreFrame(message); // SendMore option is ignored
var buffer = new byte[16];
int bytesRead = clientSocket.Receive(buffer);
Assert.Greater(bytesRead, 0);
Assert.AreEqual(Encoding.ASCII.GetString(buffer, 0, bytesRead), "HelloRaw");
}
}
示例6: Messages_From_Router_To_Dealer_With_Subscription
public void Messages_From_Router_To_Dealer_With_Subscription()
{
Console.Write("Test sending message from publisher(router) to subscribers (dealer).\n");
int maxMessage = 5;
CountdownEvent cd = new CountdownEvent(maxMessage);
string endpoint;
using (var publisher = new RouterSocket())
using (var subscriber = new DealerSocket())
using (var poller = new NetMQPoller { subscriber })
{
publisher.Bind("tcp://127.0.0.1:0");
endpoint = publisher.Options.LastEndpoint;
subscriber.Connect(endpoint);
subscriber.ReceiveReady += (sender, e) =>
{
var strs = e.Socket.ReceiveMultipartStrings();
foreach (var str in strs)
{
Console.WriteLine("Subscribe: " + str);
}
cd.Signal();
};
byte[] clientId = Encoding.Unicode.GetBytes("ClientIdTheIsLongerThen32BytesForSureAbsolutelySure");
subscriber.Options.Identity = clientId;
const string request = "Ping";
// Work around "feature" of router/dealer: the publisher does not know the subscriber exists, until it
// sends at least one message which makes it necessary to open the connection. I believe this is a
// low-level feature of the TCP/IP transport.
subscriber.SendFrame(request); // Ping.
byte[] serverId = publisher.ReceiveFrameBytes();
//Assert.AreEqual(request, publisher.ReceiveFrameString());
for (int i = 0; i < maxMessage; i++)
{
string msg = string.Format("[message: {0}]", i);
Console.Write("Publish: {0}\n", msg);
publisher.SendMoreFrame(serverId).SendFrame(msg);
//publisher.SendMoreFrame("").SendFrame(msg);
}
poller.RunAsync();
if (cd.Wait(TimeSpan.FromSeconds(10)) == false) // Blocks until _countdown.Signal has been called.
{
Assert.Fail("Timed out, this test should complete in less than 10 seconds.");
}
}
}
示例7: Messages_From_Dealer_To_Router
public void Messages_From_Dealer_To_Router()
{
int maxMessage = 5;
CountdownEvent cd = new CountdownEvent(maxMessage);
Console.Write("Test sending message from subscribers (dealer) to publisher(router).\n");
using (var publisher = new RouterSocket())
using (var subscriber = new DealerSocket())
using (var poller = new NetMQPoller { subscriber })
{
var port = publisher.BindRandomPort("tcp://*");
subscriber.Connect("tcp://127.0.0.1:" + port);
subscriber.ReceiveReady += (sender, e) =>
{
var strs = e.Socket.ReceiveMultipartStrings();
foreach (var str in strs)
{
Console.WriteLine(str);
}
cd.Signal();
};
byte[] clientId = Encoding.Unicode.GetBytes("ClientId");
subscriber.Options.Identity = clientId;
const string request = "GET /\r\n";
const string response = "HTTP/1.0 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Hello, World!";
subscriber.SendFrame(request);
byte[] serverId = publisher.ReceiveFrameBytes();
Assert.AreEqual(request, publisher.ReceiveFrameString());
for (int i = 0; i < maxMessage; i++)
{
publisher.SendMoreFrame(serverId).SendFrame(response);
}
poller.RunAsync();
if (cd.Wait(TimeSpan.FromSeconds(10)) == false) // Blocks until _countdown.Signal has been called.
{
Assert.Fail("Timed out, this test should complete in less than 10 seconds.");
}
}
}
示例8: RouterMandatoryTrueThrowsHostUnreachableException
public void RouterMandatoryTrueThrowsHostUnreachableException()
{
{
using (var dealer = new DealerSocket())
{
dealer.Options.Identity = Encoding.ASCII.GetBytes("dealer");
dealer.Bind("tcp://localhost:6667");
using (var router = new RouterSocket())
{
router.Options.RouterMandatory = true;
router.Connect("tcp://localhost:8889");
Assert.Throws<HostUnreachableException>(() => router.SendMoreFrame("dealer").SendFrame("Hello"));
}
}
}
}
示例9: RouterMandatoryFalseDiscardsMessageSilently
public void RouterMandatoryFalseDiscardsMessageSilently()
{
{
using (var dealer = new DealerSocket())
{
dealer.Options.Identity = Encoding.ASCII.GetBytes("dealer");
dealer.Bind("tcp://localhost:6667");
using (var router = new RouterSocket())
{
router.Connect("tcp://localhost:8889");
Assert.DoesNotThrow(() => router.SendMoreFrame("dealer").SendFrame("Hello"));
}
}
}
}