本文整理汇总了C#中ZmqSocket.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ZmqSocket.Close方法的具体用法?C# ZmqSocket.Close怎么用?C# ZmqSocket.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZmqSocket
的用法示例。
在下文中一共展示了ZmqSocket.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRequest
public static void SendRequest(Int32 request,ref ZmqSocket socket)
{
//ZmqSocket socket;
try
{
//socket = CreateSocket();
var message = new ZmqMessage();
message.Append(Encoding.UTF8.GetBytes(String.Format(" Hello {0}.", request)));
socket.SendMessage(message);
// TODO: add receive timeout as param
var dataResult = socket.ReceiveMessage();
Console.WriteLine(Encoding.UTF8.GetString(dataResult[0]));
Console.WriteLine(Encoding.UTF8.GetString(dataResult[1]));
}
catch (Exception ex)
{
socket.Close();
socket = CreateSocket();
Console.WriteLine(ex.ToString());
}
}
示例2: PrismRequest
public PrismRequest(ZmqContext context, string endpoint, Queue<PrismRequestItem> queue)
{
ResumeEvent = new ManualResetEvent(false);
PauseEvent = new ManualResetEvent(false);
Worker = new Thread(delegate()
{
while (Worker.IsAlive && !StopRequest)
{
if (Socket == null)
{
try
{
Socket = this.CreateSocket(context, endpoint);
}
catch (Exception e1)
{
try
{
Socket.Close();
}
catch (Exception e2)
{
}
Socket = null;
Thread.Sleep(1000);
continue;
}
}
if (OnPause)
{
PauseEvent.Reset();
PauseEvent.WaitOne();
OnPause = false;
}
if (queue.Count == 0)
{
ActiveState = false;
ResumeEvent.Reset();
ResumeEvent.WaitOne();
}
else
{
ActiveState = true;
PrismRequestItem requestItem = queue.Dequeue();
if (requestItem != null)
{
string repJson = null;
try
{
Socket.Send(requestItem.Json, Encoding.UTF8).ToString();
repJson = Socket.Receive(Encoding.UTF8);
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
catch (ZmqSocketException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
Socket = null;
}
switch (requestItem.Method)
{
case PrismRequestItem.PrismRequestMethod.GroupList:
{
GetGroupListCallback cb = (GetGroupListCallback)requestItem.ReturnCb;
try
{
PrismZmqGroupListRepPacket packet = JsonConvert.DeserializeObject<PrismZmqGroupListRepPacket>(repJson);
if (packet.Error != null)
{
cb(packet.Error, new List<string>());
}
else
{
cb(null, packet.Groups);
}
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
cb(e.ToString(), new List<string>());
}
break;
}
case PrismRequestItem.PrismRequestMethod.ChannelList:
{
GetChannelListCallback cb = (GetChannelListCallback)requestItem.ReturnCb;
try
//.........这里部分代码省略.........
示例3: PrismPoll
public PrismPoll(ZmqContext context, string endpoint)
{
ResumeEvent = new ManualResetEvent(false);
PauseEvent = new ManualResetEvent(false);
Queue = new Queue<PrismPollItem>();
Worker = new Thread(delegate()
{
while (Worker.IsAlive && !StopRequest)
{
if (Socket == null)
{
try
{
Socket = this.CreateSocket(context, endpoint);
}
catch (Exception e1)
{
try
{
Socket.Close();
}
catch (Exception e2)
{
}
Socket = null;
Thread.Sleep(1000);
continue;
}
}
if (OnPause)
{
PauseEvent.Reset();
PauseEvent.WaitOne();
OnPause = false;
}
if (Queue.Count == 0)
{
ActiveState = false;
ResumeEvent.Reset();
ResumeEvent.WaitOne();
}
else
{
ActiveState = true;
PrismPollItem pollItem = Queue.Dequeue();
if (pollItem != null)
{
string pollJson = null;
try
{
Socket.Send(pollItem.Json, Encoding.UTF8).ToString();
pollJson = Socket.Receive(Encoding.UTF8);
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
catch (ZmqSocketException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
Socket = null;
}
PollCallback cb = (PollCallback)pollItem.ReturnCb;
try
{
List<ProducerChannelValue> packet = JsonConvert.DeserializeObject<List<ProducerChannelValue>>(pollJson);
if (packet == null)
{
cb("Result packet is null", new List<ProducerChannelValue>());
}
else
{
cb(null, packet);
}
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
cb(e.ToString(), new List<ProducerChannelValue>());
}
}
}
}
try
{
Socket.Close();
}
catch (Exception e)
{
}
//.........这里部分代码省略.........
示例4: PrismSubscribe
public PrismSubscribe(ZmqContext context, string endpoint, List<string> groups)
{
Worker = new Thread(delegate()
{
while (Worker.IsAlive && !StopRequest)
{
if (Socket == null)
{
try
{
Socket = this.CreateSocket(context, endpoint, groups);
}
catch (Exception e1)
{
try
{
Socket.Close();
}
catch (Exception e2)
{
}
Socket = null;
Thread.Sleep(1000);
continue;
}
}
string data = null;
string action = "";
string json = "";
try
{
data = Socket.Receive(Encoding.UTF8);
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
continue;
}
catch (ZmqSocketException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
Socket = null;
continue;
}
try
{
string shortData = data.Substring(data.IndexOf(" ") + 1);
action = shortData.Substring(0, shortData.IndexOf(" "));
json = shortData.Substring(shortData.IndexOf(" ") + 1);
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
continue;
}
if (action.Equals("pub"))
{
if (ChannelValueEvent != null)
{
ThreadPool.QueueUserWorkItem(delegate(object target)
{
string pubJson = (string)target;
try
{
PrismZmqCommonPubPacket pubPacket = JsonConvert.DeserializeObject<PrismZmqCommonPubPacket>(pubJson);
ChannelValueEvent(this, new ProducerChannelValue(pubPacket.Group, pubPacket.Channel, pubPacket.Value));
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}, json);
}
}
else if (action.Equals("upub"))
{
if (ChannelResetEvent != null)
{
ThreadPool.QueueUserWorkItem(delegate(object target)
{
string upubJson = (string)target;
try
{
PrismZmqCommonPubPacket upubPacket = JsonConvert.DeserializeObject<PrismZmqCommonPubPacket>(upubJson);
ChannelResetEvent(this, new ProducerChannel(upubPacket.Group, upubPacket.Channel));
}
catch (SystemException e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}, json);
}
//.........这里部分代码省略.........