Skip to content
Snippets Groups Projects
Commit d3acaa8f authored by daniel's avatar daniel
Browse files

Switch to zmq req/rep model

parent 38b3edc9
No related branches found
No related tags found
No related merge requests found
...@@ -67,35 +67,39 @@ ...@@ -67,35 +67,39 @@
* 5: Goto 2 * 5: Goto 2
*/ */
static void fade(void *publisher) static void handle(void *sender)
{ {
int i = 0; int i = 0;
struct pixel pix = { .x = 0, .y = 0, .bright = 255 }; struct pixel pix = { .x = 0, .y = 0, .bright = 255 };
while (1) { while (1) {
i = (i + 1) % (20*300); i = (i + 1) % (28*300);
if (i == 0) if (i == 0)
pix.bright = 255 - pix.bright; pix.bright = 255 - pix.bright;
pix.x = i / 20; pix.x = i / 28;
pix.y = i % 20; pix.y = i % 28;
zmq_send(publisher, &pix, sizeof(pix), 0); zmq_send(sender, &pix, sizeof(pix), 0);
zmq_recv(sender, &pix, sizeof(pix), 0);
printf("(%u, %u): bright=%02x\n", pix.x, pix.y, pix.bright); printf("(%u, %u): bright=%02x\n", pix.x, pix.y, pix.bright);
usleep(1000); usleep(10000);
} }
} }
int main(void) int main(int argc, char *argv[])
{ {
void *context = zmq_ctx_new (); void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB); void *sender = zmq_socket (context, ZMQ_REQ);
int rc; int rc;
rc = zmq_bind (publisher, "tcp://*:5556"); if (argc != 2)
exit(1);
rc = zmq_connect (sender, argv[1]);
if (rc < 0) if (rc < 0)
perror("zmq_bind"); perror("zmq_bind");
fade(publisher); handle(sender);
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment