本文整理汇总了C#中NetMQSocket.TrySendFrame方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQSocket.TrySendFrame方法的具体用法?C# NetMQSocket.TrySendFrame怎么用?C# NetMQSocket.TrySendFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQSocket
的用法示例。
在下文中一共展示了NetMQSocket.TrySendFrame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessageAndData
public static void SendMessageAndData(NetMQSocket socket, MmiMessage message)
{
message.TimeStamp = DateTime.Now;
var values = message.Values;
if (values != null)
{
if (message.Shape == null)
{
var shape = new int[values.Rank];
for (var i = 0; i < values.Rank; i++)
{
shape[i] = values.GetLength(i);
}
message.Shape = shape;
}
if (string.IsNullOrEmpty(message.DataType))
{
message.DataType = GetDataTypeName(values.GetValue(0).GetType());
}
}
var json = message.ToJson();
if (values == null)
{
lock (socket)
{
if (!socket.TrySendFrame(Timeout, json))
{
throw new NetMQException("Timeout during send");
}
}
}
else
{
lock (socket)
{
var bytes = ArrayToBytes(values);
if (!socket.TrySendFrame(Timeout, json, true))
{
throw new NetMQException("Timeout during send");
}
if (!socket.TrySendFrame(Timeout, bytes))
{
throw new NetMQException("Timeout during send");
}
}
}
}
示例2: SendMessage
public static void SendMessage(NetMQSocket socket, object o, Array values = null)
{
var json = JsonConvert.SerializeObject(o);
lock (socket)
{
if (values == null)
{
if (!socket.TrySendFrame(Timeout, json))
{
throw new NetMQException("Timeout during send");
}
}
else
{
var bytes = ArrayToBytes(values);
if (!socket.TrySendFrame(Timeout, json, true))
{
throw new NetMQException("Timeout during send");
}
if (!socket.TrySendFrame(Timeout, bytes))
{
throw new NetMQException("Timeout during send");
}
}
}
}