• 2013-10-06

    Build a web chat app with icomet

    Views: 11909 | No Comments

    icomet(https://github.com/ideawu/icomet) is HTTP a server-push comet solution, it supports all popular browsers and OSes, including Safari/iOS(iPhone, iPad, iPod), Safari/Mac, IE/Windows, Chrome, Firefox/Mac, Windows.

    icomet is written in C++, built with libevent, and is totally open sourced.

    Building a web chat with icomet is very easy, the provided JavaScript client library is easy to use:

    var comet = new iComet({
        channel: 'abc',
        signUrl: 'http://127.0.0.1:8000/sign',
        subUrl: 'http://127.0.0.1:8100/sub',
        callback: function(msg){
            // on server push
            alert(msg.content);
        }
    });
    

    You can see the Live Demo here: http://www.ideawu.com/icomet/chat.html

    Posted by ideawu at 2013-10-06 14:41:02 Tags: , ,
  • 2013-09-28

    The super fast Tovi 1.5 is ready!

    Views: 6415 | No Comments

    Tovi 1.5 is now available on Mac App Store, this version makes it super fast to open more than 10000 images withing 1 second!

    No hesitate to upgrade now: http://tovi.ideawu.com/

    Tovi is a Mac image viewer, it can play gif animation, image slideshow, etc.

    Posted by ideawu at 2013-09-28 17:52:12 Tags:
  • 2013-09-28

    How to deal with git clone error?

    Views: 6457 | No Comments

    I ran into a github HTTPS clone error as this:

    $ git clone https://github.com/ideawu/ssdb.git
    Initialized empty Git repository in /xxx/.git/
    Cannot get remote repository information.
    Perhaps git-update-server-info needs to be run there?
    

    Try to use this instead: git clone git://github.com/ideawu/ssdb.git, problem solved.

    DO NOT copy the git url from github, because it is in the form of: git@github.com:ideawu/ssdb.git, this need you to set up a LOT of things! Using git://github.com/xxx/yyy.git is the easiest way to clone a read-only repo annonymous.

    Posted by ideawu at 16:56:00 Tags:
  • 2013-09-17

    Notify libevent HTTP server on client close

    Views: 9791 | No Comments

    Although we can set a close callback on HTTP connection, but the HTTP server is not notified if client close unexpetedly, such as CTRL+C.

     evhttp_connection_set_closecb(req->evcon, on_close, NULL);
    

    Because libevent called bufferevent_disable(evon, EV_READ) to stop read on the connection, so the server would not know the client close by read() returns 0, or send() causes SIGPIPE.

    All you need to is to re-enable EV_READ on that connection:

    struct bufferevent *bev = evhttp_connection_get_bufferevent(req->evcon);
    bufferevent_enable(bev, EV_READ);
    
    Posted by ideawu at 2013-09-17 13:45:33 Tags:
  • 2013-09-11

    Libevent HTTP client example

    Views: 15658 | 3 Comments

    This is a simple HTTP client written in C with libevent2, the client makes a HTTP request to a web server, and print out the response HTML text. Here’s the codes:

    #include <stdio.h>
    #include <stdlib.h>
    #include <signal.h>
    #include <unistd.h>
    #include <evhttp.h>
    #include <event2/event.h>
    #include <event2/http.h>
    #include <event2/bufferevent.h>
    
    void http_request_done(struct evhttp_request *req, void *arg){
        char buf[1024];
        int s = evbuffer_remove(req->input_buffer, &buf, sizeof(buf) - 1);
        buf[s] = '\0';
        printf("%s", buf);
        // terminate event_base_dispatch()
        event_base_loopbreak((struct event_base *)arg);
    }
    
    int main(int argc, char **argv){
        struct event_base *base;
        struct evhttp_connection *conn;
        struct evhttp_request *req;
    
        base = event_base_new();
        conn = evhttp_connection_base_new(base, NULL, "127.0.0.1", 8080);
        req = evhttp_request_new(http_request_done, base);
    
        evhttp_add_header(req->output_headers, "Host", "localhost");
        //evhttp_add_header(req->output_headers, "Connection", "close");
    
        evhttp_make_request(conn, req, EVHTTP_REQ_GET, "/index.php?id=1");
        evhttp_connection_set_timeout(req->evcon, 600);
        event_base_dispatch(base);
    
        return 0;
    }
    
    Posted by ideawu at 2013-09-11 21:55:59 Tags:
|<<<34567891011>>>| 7/19 Pages, 91 Results.