-
Notifications
You must be signed in to change notification settings - Fork 750
/
Copy pathRadioDish.cs
70 lines (56 loc) · 1.83 KB
/
RadioDish.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
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Threading;
using System.Threading.Tasks;
using NetMQ.Sockets;
using Xunit;
using Xunit.Abstractions;
namespace NetMQ.Tests
{
public class RadioDish
{
[Fact]
public void TestTcp()
{
using var radio = new RadioSocket();
using var dish = new DishSocket();
dish.Join("2");
int port = radio.BindRandomPort("tcp://*");
dish.Connect($"tcp://127.0.0.1:{port}");
Thread.Sleep(100);
radio.Send("1", "HELLO");
radio.Send("2", "HELLO");
var (group,msg) = dish.ReceiveString();
Assert.Equal("2", group);
Assert.Equal("HELLO", msg);
}
[Fact]
public void TestBlocking()
{
using var radio = new RadioSocket();
using var dish = new DishSocket();
dish.Join("2");
radio.Bind("inproc://test-radio-dish");
dish.Connect("inproc://test-radio-dish");
radio.Send("1", "HELLO");
radio.Send("2", "HELLO");
var (group,msg) = dish.ReceiveString();
Assert.Equal("2", group);
Assert.Equal("HELLO", msg);
}
[Fact]
public async Task TestAsync()
{
using var radio = new RadioSocket();
using var dish = new DishSocket();
dish.Join("2");
int port = radio.BindRandomPort("tcp://*");
dish.Connect($"tcp://127.0.0.1:{port}");
Thread.Sleep(100);
await radio.SendAsync("1", "HELLO");
await radio.SendAsync("2", "HELLO");
var (group,msg) = await dish.ReceiveStringAsync();
Assert.Equal("2", group);
Assert.Equal("HELLO", msg);
}
}
}