Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit e8ebd02cdd5c9371f8e42520936895ac447383ce 0 parents
@abedra authored
2  .gitignore
@@ -0,0 +1,2 @@
+server
+client
11 Makefile
@@ -0,0 +1,11 @@
+all: server client
+
+server:
+ gcc -o server bungleo-server.c -lzmq -ltofu
+
+client:
+ gcc -o client bungleo-client.c -lzmq -ljson
+
+clean:
+ rm server
+ rm client
55 README.md
@@ -0,0 +1,55 @@
+# bungle-o
+
+## Notes
+
+At the moment this only runs on linux. The Tofu library doesn't yet compile against OS X. Once that is resolved everything should work properly on OS X
+
+## Dependencies
+
+* For compiling the Tofu library
+** jansson
+
+ wget http://www.digip.org/jansson/releases/jansson-2.2.1.tar.gz
+ tar xvzf jansson-2.2.1.tar.gz
+ cd janson-2.2.1
+ ./configure
+ make
+ sudo make install
+
+ ** libevent
+
+ wget https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
+ tar xvzf libevent-2.0.16-stable
+ ./configure
+ make
+ sudo make install
+
+* The Tofu library itself
+
+ sudo apt-get install autoconf automake libtool libpcre3 libpcre3-dev libfcgi-dev
+ git clone git://github.com/AlexBio/Tofu
+ cd Tofu
+ ./autogen.sh
+ ./configure
+ make
+ sudo make install
+
+* 0MQ
+
+ sudo apt-get install libzmq-dev libzmq1
+
+* libjson
+
+ sudo apt-get install libjson0 libjson0-dev
+
+## Building bungle-o
+
+ make
+
+## Using bungle-o
+
+ ./server
+ ./client
+ curl -d '{"id" : "bungle-o", "message" : "test message"}' http://localhost:5000
+
+You should see a message printed from the client every time something is posted to the server
43 bungleo-client.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <zmq.h>
+#include "json/json.h"
+
+static char * zrecv(void *socket) {
+ zmq_msg_t message;
+ zmq_msg_init(&message);
+
+ if(zmq_recv(socket, &message, 0)) return(NULL);
+
+ int size = zmq_msg_size(&message);
+ char *string = malloc(size + 1);
+ memcpy(string, zmq_msg_data(&message), size);
+ zmq_msg_close(&message);
+ string[size] = 0;
+ return(string);
+}
+
+int main(void)
+{
+ void *context = zmq_init(1);
+ void *receiver = zmq_socket(context, ZMQ_PULL);
+ zmq_connect(receiver, "tcp://localhost:5555");
+
+ const char *id, *message;
+ char *string;
+ struct json_object *obj;
+
+ while(1) {
+ string = zrecv(receiver);
+ obj = json_tokener_parse(string);
+ id = json_object_get_string(json_object_object_get(obj, "id"));
+ message = json_object_get_string(json_object_object_get(obj, "message"));
+
+ printf("id is %s and message is %s\n", id, message);
+ }
+
+ zmq_close(receiver);
+ zmq_term(context);
+ return 0;
+}
42 bungleo-server.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <zmq.h>
+#include <tofu.h>
+
+static int zsend (void *socket, char *string) {
+ int rc;
+ zmq_msg_t message;
+ zmq_msg_init_size(&message, strlen(string));
+ memcpy(zmq_msg_data(&message), string, strlen(string));
+ rc = zmq_send(socket, &message, 0);
+ zmq_msg_close(&message);
+ return(rc);
+}
+
+tofu_rep_t *post(tofu_req_t *req, void *socket) {
+ tofu_rep_t *rep = tofu_rep_init();
+ int body_len;
+ char *body = tofu_body(req, &body_len);
+
+ zsend(socket, body);
+
+ tofu_status(rep, 200);
+ return rep;
+}
+
+int main() {
+ char *opts[] = { "0.0.0.0", "5000" };
+ tofu_ctx_t *ctx = tofu_ctx_init(TOFU_EVHTTP, opts);
+ void *context = zmq_init(1);
+ void *sender = zmq_socket(context, ZMQ_PUSH);
+ zmq_bind(sender, "tcp://*:5555");
+
+ tofu_handle_with(ctx, POST, "/", post, sender);
+ tofu_loop(ctx);
+
+ zmq_close(sender);
+ zmq_term(context);
+ tofu_ctx_free(ctx);
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.