本文整理汇总了C#中ZeroMQ.ZContext.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:C# ZContext.Shutdown方法的具体用法?C# ZContext.Shutdown怎么用?C# ZContext.Shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZeroMQ.ZContext
的用法示例。
在下文中一共展示了ZContext.Shutdown方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Espresso_Listener
static void Espresso_Listener(ZContext context)
{
// The listener receives all messages flowing through the proxy, on its
// pipe. In CZMQ, the pipe is a pair of ZMQ_PAIR sockets that connect
// attached child threads. In other languages your mileage may vary:
using (var listener = new ZSocket(context, ZSocketType.PAIR))
{
listener.Connect("inproc://listener");
ZError error;
ZFrame frame;
while (true)
{
if (null != (frame = listener.ReceiveFrame(out error)))
{
using (frame)
{
byte first = frame.ReadAsByte();
var rest = new byte[9];
frame.Read(rest, 0, rest.Length);
Console.WriteLine("{0} {1}", (char)first, rest.ToHexString());
if (first == 0x01)
{
// Subscribe
}
else if (first == 0x00)
{
// Unsubscribe
context.Shutdown();
}
}
}
else
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
}
}
}
示例2: Interrupt
public static void Interrupt(string[] args)
{
//
// Interrupt
//
// Author: metadings
//
if (args == null || args.Length == 0)
{
args = new string[] { "World" };
}
string name = args[0];
var error = default(ZError);
using (var context = new ZContext())
using (var responder = new ZSocket(context, ZSocketType.REP))
{
Console.CancelKeyPress += (s, ea) =>
{
ea.Cancel = true;
context.Shutdown();
};
responder.Bind("tcp://*:5555");
ZFrame request;
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo info = Console.ReadKey(true);
/* if (info.Modifiers == ConsoleModifiers.Control && info.Key == ConsoleKey.C)
{
context.Shutdown();
} /**/
if (info.Key == ConsoleKey.Escape)
{
context.Shutdown();
}
}
if (null == (request = responder.ReceiveFrame(ZSocketFlags.DontWait, out error)))
{
if (error == ZError.EAGAIN)
{
Thread.Sleep(1);
continue;
}
if (error == ZError.ETERM)
break; // Interrupted
throw new ZException(error);
}
using (request)
{
Console.Write("Received: {0}!", request.ReadString());
Thread.Sleep(512); // See also the much slower reaction
Console.WriteLine(" Sending {0}... ", name);
if (!responder.Send(new ZFrame(name), out error))
{
if (error == ZError.ETERM)
break; // Interrupted
throw new ZException(error);
}
}
}
if (error == ZError.ETERM)
{
Console.WriteLine("Terminated! You have pressed CTRL+C or ESC.");
return;
}
throw new ZException(error);
}
}
示例3: FLServer3
public static void FLServer3(string[] args)
{
//
// Freelance server - Model 3
// Uses an ROUTER/ROUTER socket but just one thread
//
// Author: metadings
//
// Prepare server socket with predictable identity
string bind_endpoint = "tcp://*:5555";
string connect_endpoint = "tcp://127.0.0.1:5555";
using (var context = new ZContext())
using (var server = new ZSocket(context, ZSocketType.ROUTER))
{
Console.CancelKeyPress += (s, ea) =>
{
ea.Cancel = true;
context.Shutdown();
};
server.IdentityString = connect_endpoint;
server.Bind(bind_endpoint);
Console.WriteLine("I: service is ready as {0}", bind_endpoint);
ZError error;
ZMessage request;
while (true)
{
if (null == (request = server.ReceiveMessage(out error)))
{
if (error == ZError.ETERM)
break; // Interrupted
throw new ZException(error);
}
using (var response = new ZMessage())
{
ZFrame identity;
using (request)
{
if (Verbose) Console_WriteZMessage("Receiving", request);
// Frame 0: identity of client
// Frame 1: PING, or client control frame
// Frame 2: request body
identity = request.Pop();
ZFrame control = request.Pop();
string controlMessage = control.ReadString();
if (controlMessage == "PING")
{
control.Dispose();
response.Add(new ZFrame("PONG"));
}
else
{
response.Add(control);
response.Add(new ZFrame("OK"));
}
}
response.Prepend(identity);
if (Verbose) Console_WriteZMessage("Sending ", response);
if (!server.Send(response, out error))
{
if (error == ZError.ETERM)
break; // Interrupted
throw new ZException(error);
}
}
}
if (error == ZError.ETERM)
{
Console.WriteLine("W: interrupted");
}
}
}