在 NetMQ 中发布/订阅时,我如何接收字节。
我正在尝试使用来自 ReceivingSocketExtensions 的扩展 byte[] ReceiveFrameBytes(),但我只是看不到它的智能感知。
我正在使用 NetMQ,它是扩展的容器命名空间。我正在使用 Nuget NetMq 包(不确定它是否相关 - 我假设它与 github 版本相同)
http://netmq.readthedocs.org/en/latest/receiving-sending/
namespace WhoCares
{
using NetMQ; // the extension are in this namespace?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
public class Subscriber
{
private Thread _coreThread;
private NetMQContext _context;
private NetMQSocket _socket;
public bool IsRunning { get; private set; }
public void Run()
{
if (IsRunning)
throw new InvalidOperationException("Already running");
_context = NetMQContext.Create();
_socket = _context.CreateSubscriberSocket();
_socket.Options.ReceiveHighWatermark = 1000;
_socket.Connect("tcp://localhost:12345");
_socket.Subscribe("TopicA");
IsRunning = true;
Core();
}
private void Core()
{
_coreThread = Thread.CurrentThread;
while (true)
{
string messageReceived = _socket.ReceiveString();
string bytesReceived = _socket.ReceiveString(); // I dont want a string..im sending bytesReceived
// i want to use
byte[] _socket.ReceiveFrameBytes();// COMPILER ERROR.. ITS IN THE EXTENSION ?
}
}
}
}
使用 NUGET 包解决它
_socket.ReceiveMessage().Pop().ToByteArray()