本文整理汇总了C#中NetMQ.Sockets.RouterSocket类的典型用法代码示例。如果您正苦于以下问题:C# RouterSocket类的具体用法?C# RouterSocket怎么用?C# RouterSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RouterSocket类属于NetMQ.Sockets命名空间,在下文中一共展示了RouterSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAndReceive
public void SendAndReceive()
{
using (var front = new RouterSocket())
using (var back = new DealerSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
var proxy = new Proxy(front, back);
Task.Factory.StartNew(proxy.Start);
using (var client = new RequestSocket())
using (var server = new ResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
}
proxy.Stop();
}
}
示例2: RouterDealerMessaging
public void RouterDealerMessaging()
{
using (var server = new RouterSocket())
using (var client = new DealerSocket())
{
int port = server.BindRandomPort("tcp://127.0.0.1");
client.Connect("tcp://127.0.0.1:" + port);
var clientOutgoingMessage = new NetMQMessage();
clientOutgoingMessage.Append("Hello");
client.SendMultipartMessage(clientOutgoingMessage);
NetMQMessage serverIncomingMessage = server.ReceiveMultipartMessage();
// number of frames should be one because first message should be identity of client
Assert.AreEqual(2, serverIncomingMessage.FrameCount);
Assert.AreEqual("Hello", serverIncomingMessage[1].ConvertToString());
var serverOutgoingMessage = new NetMQMessage();
// first adding the identity
serverOutgoingMessage.Append(serverIncomingMessage[0]);
serverOutgoingMessage.Append("World");
server.SendMultipartMessage(serverOutgoingMessage);
var incomingClientMessage = client.ReceiveMultipartMessage();
Assert.AreEqual(1, incomingClientMessage.FrameCount);
Assert.AreEqual("World", incomingClientMessage[0].ConvertToString());
}
}
示例3: RequestResponseMultipartMessageWithRetryFails
public void RequestResponseMultipartMessageWithRetryFails()
{
const string address = "tcp://127.0.0.1:50002";
const string pubAddress = "tcp://127.0.0.1:60002";
const int numTries = 5;
var requestTimeout = TimeSpan.FromMilliseconds(100);
var requestMessage = new NetMQMessage(1);
requestMessage.Append("Hi");
using (var progressPublisher = new PublisherSocket(pubAddress))
using (var progressSubscriber = new SubscriberSocket(pubAddress))
using (var server = new RouterSocket(address))
{
progressSubscriber.SubscribeToAnyTopic();
var progressProactor = new NetMQProactor(progressSubscriber, (socket, message) =>
Console.WriteLine("C: {0} {1:ss.fff}", message[0].ConvertToString(), DateTime.Now));
var serverProactor = new NetMQProactor(server, (socket, message) =>
{
Console.WriteLine("ResponseEcho recieved message {0} at {1:ss.fff}", message[2].ConvertToString(),
DateTime.Now);
});
using (serverProactor)
using (progressProactor)
{
var responseMessage = RequestSocket.RequestResponseMultipartMessageWithRetry(address, requestMessage,
numTries, requestTimeout, progressPublisher);
Assert.IsNull(responseMessage);
}
}
}
示例4: CheckReceiveAgainException
public void CheckReceiveAgainException()
{
using (var router = new RouterSocket())
{
router.BindRandomPort("tcp://127.0.0.1");
router.Receive(SendReceiveOptions.DontWait);
}
}
示例5: DefaultValues
public void DefaultValues()
{
using (var socket = new RouterSocket())
{
Assert.IsNull(socket.Options.Identity);
// Assert.IsNull(socket.Options.TcpAcceptFilter);
Assert.AreEqual(false, socket.Options.ReceiveMore);
}
}
示例6: Mandatory
public void Mandatory()
{
using (var router = new RouterSocket())
{
router.Options.RouterMandatory = true;
router.BindRandomPort("tcp://*");
Assert.Throws<HostUnreachableException>(() => router.SendMoreFrame("UNKNOWN").SendFrame("Hello"));
}
}
示例7: ReceiveReadyDot35Bug
public void ReceiveReadyDot35Bug()
{
// In .NET 3.5, we saw an issue where ReceiveReady would be raised every second despite nothing being received
using (var server = new RouterSocket())
{
server.BindRandomPort("tcp://127.0.0.1");
server.ReceiveReady += (s, e) => Assert.Fail("Should not receive");
Assert.IsFalse(server.Poll(TimeSpan.FromMilliseconds(1500)));
}
}
示例8: CheckTryReceive
public void CheckTryReceive()
{
using (var router = new RouterSocket())
{
router.BindRandomPort("tcp://127.0.0.1");
var msg = new Msg();
msg.InitEmpty();
Assert.IsFalse(router.TryReceive(ref msg, TimeSpan.Zero));
}
}
示例9: SendExecuteReplyMessage
public void SendExecuteReplyMessage(Message message, RouterSocket shellSocket)
{
ExecuteReplyOk executeReply = new ExecuteReplyOk()
{
ExecutionCount = this.executionCount,
Payload = new List<Dictionary<string, string>>(),
UserExpressions = new Dictionary<string, string>()
};
Message executeReplyMessage = MessageBuilder.CreateMessage(MessageTypeValues.ExecuteReply,
JsonSerializer.Serialize(executeReply), message.Header);
this.logger.Info(string.Format("Sending message to Shell {0}", JsonSerializer.Serialize(executeReplyMessage)));
MessageSender.Send(executeReplyMessage, shellSocket);
}
示例10: HandleMessage
public void HandleMessage(Message message, RouterSocket serverSocket, PublisherSocket ioPub)
{
KernelInfoRequest kernelInfoRequest = JsonSerializer.Deserialize<KernelInfoRequest>(message.Content);
Message replyMessage = new Message()
{
UUID = message.Header.Session,
ParentHeader = message.Header,
Header = MessageBuilder.CreateHeader(MessageTypeValues.KernelInfoReply, message.Header.Session),
Content = JsonSerializer.Serialize(this.CreateKernelInfoReply())
};
this.logger.Info("Sending kernel_info_reply");
MessageSender.Send(replyMessage, serverSocket);
}
示例11: CheckTrySendSucceeds
public void CheckTrySendSucceeds()
{
using (var router = new RouterSocket())
using (var dealer = new DealerSocket())
{
var port = router.BindRandomPort("tcp://127.0.0.1");
router.Options.Linger = TimeSpan.Zero;
dealer.Options.SendHighWatermark = 1;
dealer.Options.Linger = TimeSpan.Zero;
dealer.Connect("tcp://127.0.0.1:" + port);
Thread.Sleep(100);
Assert.IsTrue(dealer.TrySendFrame("1"));
}
}
示例12: CheckSendAgainException
public void CheckSendAgainException()
{
using (var router = new RouterSocket())
using (var dealer = new DealerSocket())
{
var port = router.BindRandomPort("tcp://127.0.0.1");
router.Options.Linger = TimeSpan.Zero;
dealer.Options.SendHighWatermark = 1;
dealer.Options.Linger = TimeSpan.Zero;
dealer.Connect("tcp://127.0.0.1:" + port);
#pragma warning disable 618
dealer.Send("1", dontWait: true, sendMore: false);
dealer.Send("2", dontWait: true, sendMore: false);
#pragma warning restore 618
}
}
示例13: 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();
}
}
示例14: SeparateControlSocketsObservedMessages
public void SeparateControlSocketsObservedMessages()
{
using (var front = new RouterSocket())
using (var back = new DealerSocket())
using (var controlInPush = new PushSocket())
using (var controlInPull = new PullSocket())
using (var controlOutPush = new PushSocket())
using (var controlOutPull = new PullSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
controlInPush.Bind("inproc://controlIn");
controlInPull.Connect("inproc://controlIn");
controlOutPush.Bind("inproc://controlOut");
controlOutPull.Connect("inproc://controlOut");
var proxy = new Proxy(front, back, controlInPush, controlOutPush);
Task.Factory.StartNew(proxy.Start);
using (var client = new RequestSocket())
using (var server = new ResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
}
Assert.IsNotNull(controlInPull.ReceiveFrameBytes()); // receive identity
Assert.IsEmpty(controlInPull.ReceiveFrameString()); // pull terminator
Assert.AreEqual("hello", controlInPull.ReceiveFrameString());
Assert.IsNotNull(controlOutPull.ReceiveFrameBytes()); // receive identity
Assert.IsEmpty(controlOutPull.ReceiveFrameString()); // pull terminator
Assert.AreEqual("reply", controlOutPull.ReceiveFrameString());
proxy.Stop();
}
}
示例15: HandleMessage
public void HandleMessage(Message message, RouterSocket serverSocket, PublisherSocket ioPub)
{
this.logger.Debug(string.Format("Message Content {0}", message.Content));
ExecuteRequest executeRequest = JsonSerializer.Deserialize<ExecuteRequest>(message.Content);
this.logger.Info(string.Format("Execute Request received with code {0}", executeRequest.Code));
// 1: Send Busy status on IOPub
this.SendMessageToIOPub(message, ioPub, StatusValues.Busy);
// 2: Send execute input on IOPub
this.SendInputMessageToIOPub(message, ioPub, executeRequest.Code);
// 3: Evaluate the C# code
string code = executeRequest.Code;
ExecutionResult results = this.replEngine.Execute(code);
string codeOutput = this.GetCodeOutput(results);
string codeHtmlOutput = this.GetCodeHtmlOutput(results);
Dictionary<string, object> data = new Dictionary<string, object>()
{
{"text/plain", codeOutput},
{"text/html", codeHtmlOutput}
};
DisplayData displayData = new DisplayData()
{
Data = data,
};
// 4: Send execute reply to shell socket
this.SendExecuteReplyMessage(message, serverSocket);
// 5: Send execute result message to IOPub
this.SendOutputMessageToIOPub(message, ioPub, displayData);
// 6: Send IDLE status message to IOPub
this.SendMessageToIOPub(message, ioPub, StatusValues.Idle);
this.executionCount += 1;
}