/
zmq-examples-client.adb
38 lines (34 loc) · 1.09 KB
/
zmq-examples-client.adb
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
with ZMQ.Sockets;
with ZMQ.Contexts;
with ZMQ.Messages;
with Ada.Text_IO; use Ada.Text_IO;
procedure ZMQ.examples.Client is
ctx : ZMQ.Contexts.Context;
s : ZMQ.Sockets.Socket;
begin
-- Initialise 0MQ context, requesting a single application thread
-- and a single I/O thread
ctx.Initialize (1);
-- Create a ZMQ_REP socket to receive requests and send replies
s.Initialize (ctx, Sockets.REQ);
-- Bind to the TCP transport and port 5555 on the 'lo' interface
s.Connect ("tcp://localhost:5555");
for i in 1 .. 10 loop
declare
query_string : constant String := "SELECT * FROM mytable";
query : ZMQ.Messages.Message;
begin
query.Initialize (query_string & "(" & i'Img & ");");
s.Send (query);
query.Finalize;
end;
declare
resultset : ZMQ.Messages.Message;
begin
resultset.Initialize;
s.recv (resultset);
Put_Line ('"' & resultset.getData & '"');
resultset.Finalize;
end;
end loop;
end ZMQ.Examples.Client;