Skip to content

Instantly share code, notes, and snippets.

@stonegao
Forked from hintjens/zwtfpd.c
Created May 2, 2013 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonegao/5500502 to your computer and use it in GitHub Desktop.
Save stonegao/5500502 to your computer and use it in GitHub Desktop.
// Minimal WTFP server in 0MQ
#include "czmq.h"
static void *
wtfp_server (void *args)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);
while (true) {
// Get WTFP request
zframe_t *handle = zframe_recv (router);
if (!handle)
break; // Ctrl-C interrupt
char *request = zstr_recv (router);
puts (request); // Professional Logging(TM)
free (request); // We throw this away
// Send Hello World response
zframe_send (&handle, router, ZFRAME_MORE);
zstr_send (router, "Hello, World!");
}
zctx_destroy (&ctx);
return NULL;
}
int main (void)
{
zthread_new (wtfp_server, NULL);
zctx_t *ctx = zctx_new ();
void *dealer = zsocket_new (ctx, ZMQ_DEALER);
int rc = zsocket_connect (dealer, "tcp://localhost:8080");
assert (rc != -1);
zstr_send (dealer, "GET /Hello");
char *response = zstr_recv (dealer);
puts (response);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment