forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathhwclient.cs
58 lines (50 loc) · 1.26 KB
/
hwclient.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
58
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 HWClient(string[] args)
{
//
// Hello World client
//
// Author: metadings
//
if (args == null || args.Length < 1)
{
Console.WriteLine();
Console.WriteLine("Usage: ./{0} HWClient [Endpoint]", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine();
Console.WriteLine(" Endpoint Where HWClient should connect to.");
Console.WriteLine(" Default is tcp://127.0.0.1:5555");
Console.WriteLine();
args = new string[] { "tcp://127.0.0.1:5555" };
}
string endpoint = args[0];
// Create
using (var context = new ZContext())
using (var requester = new ZSocket(context, ZSocketType.REQ))
{
// Connect
requester.Connect(endpoint);
for (int n = 0; n < 10; ++n)
{
string requestText = "Hello";
Console.Write("Sending {0}...", requestText);
// Send
requester.Send(new ZFrame(requestText));
// Receive
using (ZFrame reply = requester.ReceiveFrame())
{
Console.WriteLine(" Received: {0} {1}!", requestText, reply.ReadString());
}
}
}
}
}
}