-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_server.c
More file actions
56 lines (37 loc) · 1.14 KB
/
Copy pathagent_server.c
File metadata and controls
56 lines (37 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
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zmq.h>
#include "zhelpers.h"
#include "agent.h"
#include "config.h"
int main(int const argc,
const char ** const argv)
{
int ret;
struct Agent *agent;
void *context;
void *receiver; /* messages from monitor */
void *sender; /* messages to monitor */
char *incomming_message;
size_t msg_size;
ret = Agent_new(&agent);
if (ret != OK) return ret;
context = zmq_init(1);
receiver = zmq_socket(context, ZMQ_PULL);
zmq_connect(receiver, "tcp://localhost:5569");
sender = zmq_socket(context, ZMQ_PUSH);
zmq_connect(sender, "tcp://localhost:5558");
while (1) {
if (AGENT_DEBUG_LEVEL_1)
printf(">>> [agent]: Waiting for incomming message...\n");
incomming_message = s_recv(receiver, &msg_size);
if (AGENT_DEBUG_LEVEL_1)
printf(">>> [agent]: Incomming message:\n %s\n", incomming_message);
/* handling message */
agent->request_handler(agent, incomming_message, sender);
/* task complited */
free(incomming_message);
}
return OK;
}