Posted on 2011-08-05 14:51
xsong 阅读(1345)
评论(0) 编辑 收藏 所属分类:
linux 、
c
#include <stdio.h>
#include <stdlib.h>
#include <event.h>
#include <evhttp.h>
void generic_request_handler(struct evhttp_request *req, void *arg) {
struct evbuffer *return_buffer=evbuffer_new();
evbuffer_add_printf(return_buffer,"welcome");
evhttp_send_reply(req,HTTP_OK,"Client",return_buffer );
evbuffer_free(return_buffer);
}
int main(int argc, char **argv) {
short http_port =8082;
char *http_addr="127.0.0.1";
struct evhttp *http_serv=NULL;
event_init();
http_serv= evhttp_start(http_addr,http_port);
evhttp_set_gencb(http_serv,generic_request_handler,NULL);
event_dispatch();
return 0;
}