本文整理汇总了C#中NetMQSocket.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQSocket.Receive方法的具体用法?C# NetMQSocket.Receive怎么用?C# NetMQSocket.Receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQSocket
的用法示例。
在下文中一共展示了NetMQSocket.Receive方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoServer
protected override void DoServer(NetMQSocket socket, int messageSize)
{
for (int i = 0; i < Iterations; i++)
{
byte[] message = socket.Receive();
socket.Send(message);
}
}
示例2: ReceiveMessage
public int ReceiveMessage(NetMQSocket subscriber)
{
bool hasMore = true;
var address = string.Empty;
int i = 0;
int retValue = 0;
var buffer = subscriber.Receive(out hasMore);
while (hasMore)
{
if (i == 0)
{
address = Encoding.Unicode.GetString(buffer);
}
if (i == 1)
{
byte[] messageAsBytes = buffer;
string message = Encoding.Unicode.GetString(messageAsBytes);
if (message == "ADDSUBSCRIBER")
{
retValue = 1;
}
else
{
retValue = -1;
}
}
i++;
buffer = subscriber.Receive(out hasMore);
}
//zmqMessage = zmqOut;
return retValue;
}
示例3: DoClient
protected override long DoClient(NetMQSocket socket, int messageSize)
{
var msg = new byte[messageSize];
var watch = Stopwatch.StartNew();
for (int i = 0; i < Iterations; i++)
{
socket.Send(msg);
socket.Receive(); // ignore response
}
return watch.ElapsedTicks;
}
示例4: ProxyBetween
private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
{
var msg = new Msg();
msg.InitEmpty();
var copy = new Msg();
copy.InitEmpty();
while (true)
{
from.Receive(ref msg, SendReceiveOptions.None);
bool more = from.Options.ReceiveMore;
if (control != null)
{
copy.Copy(ref msg);
control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
}
to.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
if (!more)
{
break;
}
}
copy.Close();
msg.Close();
}
示例5: ProxyBetween
private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
{
var msg = new Msg();
msg.InitEmpty();
var copy = new Msg();
copy.InitEmpty();
while (true)
{
from.Receive(ref msg);
var more = msg.HasMore;
if (control != null)
{
copy.Copy(ref msg);
control.Send(ref copy, more);
}
to.Send(ref msg, more);
if (!more)
break;
}
copy.Close();
msg.Close();
}
示例6: Start
public async Task Start ()
{
ThrowIfDisposed ();
var ct = cancellationTokenSource.Token;
nmqPoller = new Poller ();
nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
nmqServer = nmqContext.CreateResponseSocket ();
nmqServer.Bind (Address.AbsoluteUri.TrimEnd ('/'));
serverTask = Task.Factory.StartNew (() => {
ct.ThrowIfCancellationRequested ();
while (true) {
if (ct.IsCancellationRequested) {
// clean up here
ct.ThrowIfCancellationRequested ();
}
var msg = nmqServer.Receive ();
var request = Request.Deserialize (msg);
var result = Handle (request);
byte[] output_buffer = result.Serialize ();
nmqServer.Send (output_buffer);
}
}, ct);
await serverTask;
}
示例7: DoServer
protected override void DoServer(NetMQSocket socket, int messageSize)
{
var msg = new Msg();
msg.InitEmpty();
for (int i = 0; i < Iterations; i++)
{
socket.Receive(ref msg);
socket.Send(ref msg, more: false);
}
}
示例8: WaitForMessages
private void WaitForMessages(NetMQSocket subscriberSocket)
{
while(_running)
{
try
{
byte[] bytes = subscriberSocket.Receive();
NetMQMessage message = NetMQMessage.FromBytes(bytes);
TraceMessages(message.ScaleoutMessage.Messages, "Receiving at " + _configuration.PublisherAddress);
OnReceived(0, (ulong) message.MessageId, message.ScaleoutMessage);
}
catch(TerminatingException)
{
//Noop
}
}
}
示例9: AcceptHistoricalDataRequest
/// <summary>
/// Processes incoming historical data requests.
/// </summary>
private void AcceptHistoricalDataRequest(string requesterIdentity, NetMQSocket socket)
{
//third: a serialized HistoricalDataRequest object which contains the details of the request
bool hasMore;
byte[] buffer = socket.Receive(out hasMore);
var ms = new MemoryStream();
ms.Write(buffer, 0, buffer.Length);
ms.Position = 0;
HistoricalDataRequest request = Serializer.Deserialize<HistoricalDataRequest>(ms);
//log the request
Log(LogLevel.Info, string.Format("Historical Data Request from client {0}: {7} {1} @ {2} from {3} to {4} Location: {5} {6:;;SaveToLocal}",
requesterIdentity,
request.Instrument.Symbol,
Enum.GetName(typeof(BarSize), request.Frequency),
request.StartingDate,
request.EndingDate,
request.DataLocation,
request.SaveDataToStorage ? 0 : 1,
request.Instrument.Datasource.Name));
request.RequesterIdentity = requesterIdentity;
try
{
_broker.RequestHistoricalData(request);
}
catch (Exception ex) //there's some sort of problem with fulfilling the request. Inform the client.
{
SendErrorReply(requesterIdentity, request.RequestID, ex.Message);
}
}
示例10: AcceptDataAdditionRequest
/// <summary>
/// Handles incoming data "push" requests: the client sends data for us to add to local storage.
/// </summary>
private void AcceptDataAdditionRequest(string requesterIdentity, NetMQSocket socket)
{
//final message part: receive the DataAdditionRequest object
bool hasMore;
var ms = new MemoryStream();
byte[] buffer = socket.Receive(out hasMore);
var request = MyUtils.ProtoBufDeserialize<DataAdditionRequest>(buffer, ms);
//log the request
Log(LogLevel.Info, string.Format("Received data push request for {0}.",
request.Instrument.Symbol));
//start building the reply
socket.SendMore(requesterIdentity);
socket.SendMore("PUSHREP");
try
{
_broker.AddData(request);
socket.Send("OK");
}
catch (Exception ex)
{
socket.SendMore("ERROR");
socket.Send(ex.Message);
}
}
示例11: AcceptAvailableDataRequest
/// <summary>
/// Handles requests for information on data that is available in local storage
/// </summary>
private void AcceptAvailableDataRequest(string requesterIdentity, NetMQSocket socket)
{
//get the instrument
bool hasMore;
var ms = new MemoryStream();
byte[] buffer = socket.Receive(out hasMore);
var instrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);
//log the request
Log(LogLevel.Info, string.Format("Received local data storage info request for {0}.",
instrument.Symbol));
//and send the reply
var storageInfo = _broker.GetAvailableDataInfo(instrument);
socket.SendMore(requesterIdentity);
socket.SendMore("AVAILABLEDATAREP");
socket.SendMore(MyUtils.ProtoBufSerialize(instrument, ms));
socket.SendMore(BitConverter.GetBytes(storageInfo.Count));
foreach (StoredDataInfo sdi in storageInfo)
{
socket.SendMore(MyUtils.ProtoBufSerialize(sdi, ms));
}
socket.Send("END");
}