以即时通信为代表的web应用程序对数据的Low Latency要求,传统的基于轮询的方式已经无法满足,而且也会带来不好的用户体验。于是一种基于http长连接的“服务器推”技术便被hack出来。这种技术被命名为Comet,这个术语由Dojo Toolkit 的项目主管Alex Russell在博文Comet: Low Latency Data for the Browser首次提出,并沿用下来。
wget --no-check-certificate [url=https://github.com/ideawu/icomet/archive/master.zip]https://github.com/ideawu/icomet/archive/master.zip[/url]
unzip master.zip
cd icomet-master/
make
Start icomet server:
./icomet-server icomet.conf
# or run as daemon
./icomet-server -d icomet.conf
# stop
./icomet-server icomet.conf -s stop
Make a test via curl:
curl -v "http://127.0.0.1:8100/sub?cname=12&seq=1"
# open another terminal
curl -v "http://127.0.0.1:8000/push?cname=12&content=hi"
2Web端JavaScript调用方法
var comet = new iComet({
channel: 'abc',
signUrl: 'http://127.0.0.1:8000/sign',
subUrl: 'http://127.0.0.1:8100/sub',
callback: function(content){
// on server push
alert(content);
}
});
You can integrate icomet with nginx. If you are running you website on port 80 with domain www.test.com. That is you visit your website home page with this url:
http://www.test.com/
Then you want to run icomet on the same server with port 80, for the concern of firewall issue. You can config nginx to pass request to icomet: