How does facebook, gmail send the real time notification?

前端 未结 5 1005
梦毁少年i
梦毁少年i 2020-11-22 09:55

I have read some posts about this topic and the answers are comet, reverse ajax, http streaming, server push, etc.

How does incoming mail notification on Gmail works

5条回答
  •  广开言路
    2020-11-22 10:47

    According to a slideshow about Facebook's Messaging system, Facebook uses the comet technology to "push" message to web browsers. Facebook's comet server is built on the open sourced Erlang web server mochiweb.

    In the picture below, the phrase "channel clusters" means "comet servers".

    System overview

    Many other big web sites build their own comet server, because there are differences between every company's need. But build your own comet server on a open source comet server is a good approach.

    You can try icomet, a C1000K C++ comet server built with libevent. icomet also provides a JavaScript library, it is easy to use as simple as:

    var comet = new iComet({
        sign_url: 'http://' + app_host + '/sign?obj=' + obj,
        sub_url: 'http://' + icomet_host + '/sub',
        callback: function(msg){
            // on server push
            alert(msg.content);
        }
    });
    

    icomet supports a wide range of Browsers and OSes, including Safari(iOS, Mac), IEs(Windows), Firefox, Chrome, etc.

提交回复
热议问题