forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 23
/
interrupt.cs
47 lines (37 loc) · 1.2 KB
/
interrupt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// Shows how to handle Ctrl-C
//
// Author: Tomas Roos
// Email: ptomasroos@gmail.com
using System;
using System.Text;
using System.Threading;
using ZMQ;
namespace ZMQGuide
{
internal class Program
{
public static void Main(string[] args)
{
using (var context = new Context(1))
{
using (Socket replyer = context.Socket(SocketType.REP))
{
replyer.Bind("tcp://*:5555");
bool interrupted = false;
Console.CancelKeyPress += delegate { interrupted = true; };
const string replyMessage = "World";
while (!interrupted)
{
string message = replyer.Recv(Encoding.Unicode);
Console.WriteLine("Received request: {0}", message);
// Simulate work, by sleeping
Thread.Sleep(1000);
// Send reply back to client
replyer.Send(replyMessage, Encoding.Unicode);
}
}
}
}
}
}