0 Replies - 334 Views - Last Post: 01 May 2011 - 04:17 AM Rate Topic: -----

#1 heady89  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 164
  • Joined: 31-December 09

long polling question

Posted 01 May 2011 - 04:17 AM

Hi,

I'll just post this in a thread of its own to make it more clear.
When using longpolling you establish a simulated constant connection to the server
but if i am using the script below for instance it would constantly return new data
and instantly keep refreshing the shoutbox.

It's what i want indeed but how is it any better than just polling from the client?
Since this one returns results all the time, isn't it just restarting the connection all the time anyway?


I am just trying to grasp how to / when to utilize long polling, polling etc.

Cheers

Server
		$time = time();
		while((time() - $time) < 30) 
		{
		    // Query for new data
		    $data = $shoutboxView->DrawShoutbox($shoutboxHandler->GetShoutboxMessages(),$isLogged);
		 
		    // if we have new data return it
		    if(!empty($data)) 
		    {
		        echo $data;
		        break;
		    }
		 
		    usleep(25000);
		}



Client
var lpOnComplete = function(response)
{
    $("#shoutboxFullWrapper").html(response);
    lpStart();
};
 
var lpStart = function() 
{
    $.post('AjaxController.php', {}, lpOnComplete, 'html');
};
 
$(document).ready(lpStart);



Is This A Good Question/Topic? 0
  • +

Page 1 of 1