免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1736 | 回复: 1
打印 上一主题 下一主题

求助:网页发消息(请求)接口问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-01 09:53 |只看该作者 |倒序浏览
小弟刚到公司上班,我们老大叫我利用libevent里面的一些接口,写一个从公司网页上发送消息(请求)到Psi(时通讯用户连线聊天)的接口程序,借鉴的libevent接口为如下所示,小弟这方面真是一点不懂啊,可能连问题都说不清楚,不好意思,希望那个高手大哥指点指点。。。。万分感谢
#include <sys/types.h>
#include <sys/time.h>
#include <stdlib.h>
#include <err.h>

#include <event.h>
#include <evhttp.h>

void root_handler(struct evhttp_request *req, void *arg)
{
        struct evbuffer *buf;

        buf = evbuffer_new();
        if (buf == NULL)
                err(1, “failed to create response buffer”);
        evbuffer_add_printf(buf, “Hello World!\n”);
        evhttp_send_reply(req, HTTP_OK, “OK”, buf);
}




void generic_handler(struct evhttp_request *req, void *arg)
{
        struct evbuffer *buf;

        buf = evbuffer_new();
        if (buf == NULL)
                err(1, “failed to create response buffer”);
        evbuffer_add_printf(buf, “Requested: %s\n”, evhttp_request_uri(req));
        evhttp_send_reply(req, HTTP_OK, “OK”, buf);
}




int main(int argc, char **argv)
{

        struct evhttp *httpd;

        event_init();
        httpd = evhttp_start(“0.0.0.0″, 8080);

        /* Set a callback for requests to “/”. */
        evhttp_set_cb(httpd, “/”, root_handler, NULL);

        /* Set a callback for all other requests. */
        evhttp_set_gencb(httpd, generic_handler, NULL);

        event_dispatch();

        /* Not reached in this code as it is now. */

        evhttp_free(httpd);

        return 0;
}

论坛徽章:
0
2 [报告]
发表于 2008-02-03 11:55 |只看该作者

回复 #1 不及格 的帖子

你的问题是什么?说清楚点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP