本文整理汇总了C#中NetMQMessage.Append方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQMessage.Append方法的具体用法?C# NetMQMessage.Append怎么用?C# NetMQMessage.Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQMessage
的用法示例。
在下文中一共展示了NetMQMessage.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public Task Send(ArraySegment<byte> data, params object[] connectionIDs)
{
var task = new Task(() =>
{
var msg = new NetMQMessage();
if (_socket is RouterSocket)
{
msg.Append(new byte[0]);
msg.AppendEmptyFrame();
}
msg.Append(data.Count == data.Array.Length ? data.Array : data.ToArray());
if (connectionIDs.Length <= 0)
_socket.SendMultipartMessage(msg);
else
{
foreach (var connection in connectionIDs)
{
if (_socket is RouterSocket && connection is byte[])
{
msg.Pop();
msg.Push(((byte[])connection));
}
_socket.SendMultipartMessage(msg);
}
}
});
task.Start(_scheduler);
return task;
}
示例2: CreateMessage
public static NetMQMessage CreateMessage(string topic, byte[] data)
{
var message = new NetMQMessage();
if (!string.IsNullOrEmpty(topic)) message.Append(Encoding.Unicode.GetBytes(topic));
message.Append(data);
return message;
}
示例3: AppendInt32
public void AppendInt32()
{
NetMQMessage message = new NetMQMessage();
message.Append("Hello");
message.Append(5);
Assert.AreEqual(4, message[1].MessageSize);
Assert.AreEqual(5, message[1].ConvertToInt32());
}
示例4: CallMethod_Using_NProxyWrapper_ReadMessageWithRawActor
public void CallMethod_Using_NProxyWrapper_ReadMessageWithRawActor()
{
waitHandle.Reset();
using (var context = NetMQContext.Create())
{
using (var exchange = new Exchange(context))
{
exchange.Start();
var queueDevice = new QueueDevice(
context,
Pipe.PubSubControlBackAddressServer,
Pipe.PubSubControlFrontAddressServer,
DeviceMode.Threaded);
queueDevice.Start();
Thread.Sleep(200);
var task = Task.Run(() =>
{
return RunSubscriber(context);
});
using (var actor = new Actor(context, new BinarySerializer()))
{
using (var syncService = context.CreateResponseSocket())
{
syncService.Connect(Pipe.PubSubControlFrontAddressClient);
for (int i = 0; i < 1; i++)
{
syncService.Receive();
syncService.Send(string.Empty);
}
var order = actor.CreateInstance<IOrder>(typeof(Order));
Assert.IsInstanceOfType(order, typeof(IOrder));
order.UpdateDescription("XXX"); //called without exception
waitHandle.WaitOne();
var netMqMessage = new NetMQMessage();
netMqMessage.Append(new NetMQFrame(string.Empty));
netMqMessage.Append(new NetMQFrame("shutdownallactors"));
actor.OutputChannel.SendMessage(netMqMessage);
//actor.SendKillSignal(actor.Serializer, actor.OutputChannel, string.Empty);
}
}
Thread.Sleep(200);
queueDevice.Stop(true);
exchange.Stop(true);
}
}
}
示例5: AppendInt64
public void AppendInt64()
{
long num = (long)int.MaxValue + 1;
NetMQMessage message = new NetMQMessage();
message.Append("Hello");
message.Append(num);
Assert.AreEqual(8, message[1].MessageSize);
Assert.AreEqual(num, message[1].ConvertToInt64());
}
示例6: Run
public void Run()
{
using (NetMQContext ctx = NetMQContext.Create())
{
using (var server = ctx.CreateRouterSocket())
{
server.Bind("tcp://127.0.0.1:5556");
CreateClient(ctx, "A_");
CreateClient(ctx, "B_");
CreateClient(ctx, "C_");
CreateClient(ctx, "D_");
while (true)
{
var clientMessage = server.ReceiveMessage();
Console.WriteLine("========================");
Console.WriteLine(" INCOMING CLIENT MESSAGE ");
Console.WriteLine("========================");
for (int i = 0; i < clientMessage.FrameCount; i++)
{
Console.WriteLine("Frame[{0}] = {1}", i,
clientMessage[i].ConvertToString());
}
var clientAddress = clientMessage[0];
var clientOriginalMessage = clientMessage[2].ConvertToString();
string response = string.Format("{0} back from server",
clientOriginalMessage);
// "B_" client is special
if (clientOriginalMessage.StartsWith("B_"))
{
response = string.Format(
"special Message for 'B' back from server");
}
var messageToClient = new NetMQMessage();
messageToClient.Append(clientAddress);
messageToClient.AppendEmptyFrame();
messageToClient.Append(response);
server.SendMessage(messageToClient);
}
}
}
Console.ReadLine();
}
示例7: ToNetMQMessage
public virtual NetMQMessage ToNetMQMessage()
{
NetMQMessage message = new NetMQMessage();
message.Append(new byte[] { (byte)HandshakeType });
return message;
}
示例8: 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);
}
}
}
示例9: DesktopClient_WillAccept_SinglePartMessages
public void DesktopClient_WillAccept_SinglePartMessages()
{
Queue<Packet> packets = new Queue<Packet>();
// Mock the the message handler processor
var messageHandler = new Mock<IDesktopMessageHandler>();
messageHandler.Setup(mh => mh.DisplayLogPacket(It.IsAny<LogPacket>())).Callback(
(LogPacket packet) =>
{
packets.Enqueue(packet);
}).Verifiable();
// Setup Client
StartClientThread(messageHandler.Object);
using (PushSocket server = new PushSocket("@tcp://*:" + _port))
{
var message = new NetMQMessage();
message.Append(JsonConvert.SerializeObject(new LogPacket()));
server.SendMultipartMessage(message);
}
// Give NetMQ time to send the message
Thread.Sleep(500);
Assert.IsTrue(packets.Count == 1);
}
示例10: Main
private static void Main(string[] args)
{
using (NetMQContext context = NetMQContext.Create())
{
ReliableServer server = new ReliableServer(context, "tcp://*:6669");
while (true)
{
NetMQMessage message = new NetMQMessage();
message.Append("A");
message.Append(new Random().Next().ToString());
server.Publish(message);
Thread.Sleep(1000);
}
}
}
示例11: SendMoreTest
public void SendMoreTest()
{
using (NetMQContext ctx = NetMQContext.Create())
{
using (var server = ctx.CreateResponseSocket())
{
server.Bind("tcp://127.0.0.1:5556");
using (var client = ctx.CreateRequestSocket())
{
client.Connect("tcp://127.0.0.1:5556");
//client send message
client.SendMore("A");
client.Send("Hello");
//server receive 1st part
bool more;
string m = server.ReceiveString(out more);
Assert.AreEqual("A", m);
Assert.IsTrue(more);
//server receive 2nd part
string m2 = server.ReceiveString(out more);
Assert.AreEqual("Hello", m2);
Assert.False(more);
//server send message, this time use NetMqMessage
//which will be sent as frames if the client calls
//ReceieveMessage()
var m3 = new NetMQMessage();
m3.Append("From");
m3.Append("Server");
server.SendMessage(m3);
//client receive
var m4 = client.ReceiveMessage();
Assert.AreEqual(2, m4.FrameCount);
Assert.AreEqual("From", m4[0].ConvertToString());
Assert.AreEqual("Server", m4[1].ConvertToString());
}
}
}
}
示例12: TwoFrames
public void TwoFrames()
{
var message = new NetMQMessage();
Assert.AreEqual(0, message.FrameCount);
Assert.True(message.IsEmpty);
message.Append("Hello");
message.Append("Hello2");
Assert.AreEqual("Hello", message[0].ConvertToString());
Assert.AreEqual("Hello2", message[1].ConvertToString());
Assert.False(message.IsEmpty);
Assert.AreSame(message[0], message.First);
Assert.AreSame(message[1], message.Last);
Assert.AreNotSame(message[0], message[1]);
Assert.AreEqual(2, message.FrameCount);
}
示例13: ClientToServerMessage
public void ClientToServerMessage()
{
NetMQMessage plainMessage = new NetMQMessage();
plainMessage.Append("Hello");
NetMQMessage cipherMessage = m_clientSecureChannel.EncryptApplicationMessage(plainMessage);
NetMQMessage decryptedMessage = m_serverSecureChannel.DecryptApplicationMessage(cipherMessage);
Assert.AreEqual(decryptedMessage[0].ConvertToString(), plainMessage[0].ConvertToString());
Assert.AreEqual(decryptedMessage[0].ConvertToString(), "Hello");
}
示例14: ReceiveMessage
public static void ReceiveMessage(this IReceivingSocket socket, NetMQMessage message, bool dontWait = false)
{
message.Clear();
bool more = true;
while (more)
{
byte[] buffer = socket.Receive(dontWait, out more);
message.Append(buffer);
}
}
示例15: ChangeThePadding
public void ChangeThePadding()
{
NetMQMessage plainMessage = new NetMQMessage();
plainMessage.Append("Hello");
NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage);
cipherMessage.Last.Buffer[15]++;
NetMQSecurityException exception = Assert.Throws<NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage));
Assert.AreEqual(NetMQSecurityErrorCode.MACNotMatched, exception.ErrorCode);
}