forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interrupt.cs and refactored rrbroker.cs
- Loading branch information
1 parent
351e91d
commit eb0c174
Showing
2 changed files
with
88 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters