-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmsread.pas
More file actions
49 lines (40 loc) · 1.14 KB
/
msread.pas
File metadata and controls
49 lines (40 loc) · 1.14 KB
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
{
Reading from multiple sockets
This version uses a simple recv loop
@author cpicanco <cpicanco@ufpa.br>
}
program msread;
uses SysUtils, zmq;
var
context, receiver, subscriber: Pointer;
filter : string = '10001';
msg : array [0..255] of Char;
size: Integer;
begin
// Connect to task ventilator
context := zmq_ctx_new;
receiver := zmq_socket(context, ZMQ_PULL);
zmq_connect(receiver, 'tcp://localhost:5557');
// Connect to weather server
subscriber := zmq_socket(context, ZMQ_SUB);
zmq_connect(subscriber, 'tcp://localhost:5556');
zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, @filter[1], Length(filter));
// Process messages from both sockets
// We prioritize traffic from the task ventilator
repeat
FillChar(msg, SizeOf(msg), 0);
repeat
size := zmq_recv(receiver, @msg, 255, ZMQ_DONTWAIT);
// Process task
until size = -1;
repeat
size := zmq_recv(subscriber, @msg, 255, ZMQ_DONTWAIT);
// Process weather update
until size = -1;
// No activity, so sleep for 1 msec
Sleep(1);
until False;
zmq_close(receiver);
zmq_close(subscriber);
zmq_ctx_destroy (context);
end.