-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwuserver.pas
44 lines (35 loc) · 967 Bytes
/
wuserver.pas
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
{
Weather update server
Binds PUB socket to tcp://*:5556
Publishes random weather updates
@author cpicanco <[email protected]>
}
program wuserver;
{$MODE objfpc}{$H+}
uses SysUtils, zmq, zmq.helpers;
var
context : Pointer;
publisher : Pointer;
rc : integer;
zipcode, temperature, relhumidity : integer;
update : string[20];
begin
// Prepare our context and publisher
context := zmq_ctx_new;
publisher := zmq_socket(context, ZMQ_PUB);
rc := zmq_bind(publisher, 'tcp://*:5556');
Assert(rc = 0);
// Initialize random number generator
Randomize;
repeat
// Get values that will fool the boss
zipcode := RandOf(100000);
temperature := RandOf(215) - 80;
relhumidity := RandOf(50) + 10;
// Send message to all subscribers
WriteStr(update, Format('%5d %d %d', [zipcode, temperature, relhumidity]));
s_send(publisher, update);
until False;
zmq_close(publisher);
zmq_ctx_destroy(context);
end.