forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 23
/
hwserver.cs
57 lines (49 loc) · 1.08 KB
/
hwserver.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
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ZeroMQ;
namespace Examples
{
static partial class Program
{
public static void HWServer(string[] args)
{
//
// Hello World server
//
// Author: metadings
//
if (args == null || args.Length < 1)
{
Console.WriteLine();
Console.WriteLine("Usage: ./{0} HWServer [Name]", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine();
Console.WriteLine(" Name Your name. Default: World");
Console.WriteLine();
args = new string[] { "World" };
}
string name = args[0];
// Create
using (var context = new ZContext())
using (var responder = new ZSocket(context, ZSocketType.REP))
{
// Bind
responder.Bind("tcp://*:5555");
while (true)
{
// Receive
using (ZFrame request = responder.ReceiveFrame())
{
Console.WriteLine("Received {0}", request.ReadString());
// Do some work
Thread.Sleep(1);
// Send
responder.Send(new ZFrame(name));
}
}
}
}
}
}