我处于研究新技术的位置,所以我听说过 Long polling,node.js。
我需要创建一个使用long polling
.
在这个项目的每个页面上,我都需要使用轮询,实际上它通过 POP 检查是否有新的电子邮件。
所以我认为我需要做以下事情
- 向服务器调用ajax请求
- 服务器收到请求并检查是否有新的电子邮件
- 如果有一个新的邮件服务器响应它的详细信息
- 如果没有新的电子邮件服务器在某个时间开始休眠并再次检查,直到收到一封新电子邮件。
所以像这样
$(document).ready(function(){
is_there_new_mail();
function is_there_new_mail()
{
$.get(url,function(data){
if(data ==true)
{
//do some actions and call again
is_there_new_mail();
}
});
}
});
在服务器中是这样的
function check_mail()
{
//processing and checking is there a new mail on inbox
return $is_mail = $this->_new_mail()?true:false;
}
function receiver()
{
if($check_mail())
{
//send to client..
}
else
{
//sleep sometime and call mail function
}
}
我听说这样做会在服务器上打开许多连接,如果我们使用 node.js,我们可以在一个连接中管理它。
我正在使用 Codeigniter,对 node.js 来说真的很陌生。
如何使用 codeigniter 实现 node.js,或者您能否建议我更多关于此场景的信息。